Skip to content

Commit f6c9ee5

Browse files
authored
Merge pull request github#84 from github/igfoo/unit
Kotlin: Fix handling of objects in external dependencies
2 parents c803328 + 5a9dc25 commit f6c9ee5

File tree

3 files changed

+17
-18
lines changed

3 files changed

+17
-18
lines changed

java/kotlin-extractor/src/main/kotlin/KotlinExtractorExtension.kt

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,7 @@ open class KotlinFileExtractor(
906906
if(!c.isNonCompanionObject) {
907907
logger.warn(Severity.ErrorSevere, "Using instance for non-object class")
908908
}
909-
val classId = useClassSource(c)
909+
val classId = useClassInstance(c, listOf()).classLabel
910910
val instanceName = "INSTANCE"
911911
val instanceLabel = "@\"field;{$classId};$instanceName\""
912912
val instanceId: Label<DbField> = tw.getLabelFor(instanceLabel)
@@ -1657,20 +1657,15 @@ open class KotlinFileExtractor(
16571657
// field that we are accessing here.
16581658
val exprParent = parent.expr(e, callable)
16591659
val c: IrClass = e.symbol.owner
1660-
// TODO: If this is enabled for Unit then it currently makes tests fail
1661-
if(c.name.asString() == "Unit") {
1662-
logger.warnElement(Severity.ErrorSevere, "Unit object not handled yet", e)
1663-
} else {
1664-
val instance = useObjectClassInstance(c)
1660+
val instance = useObjectClassInstance(c)
16651661

1666-
val id = tw.getFreshIdLabel<DbVaraccess>()
1667-
val type = useType(e.type)
1668-
val locId = tw.getLocation(e)
1669-
tw.writeExprs_varaccess(id, type.javaResult.id, type.kotlinResult.id, exprParent.parent, exprParent.idx)
1670-
tw.writeHasLocation(id, locId)
1662+
val id = tw.getFreshIdLabel<DbVaraccess>()
1663+
val type = useType(e.type)
1664+
val locId = tw.getLocation(e)
1665+
tw.writeExprs_varaccess(id, type.javaResult.id, type.kotlinResult.id, exprParent.parent, exprParent.idx)
1666+
tw.writeHasLocation(id, locId)
16711667

1672-
tw.writeVariableBinding(id, instance.id)
1673-
}
1668+
tw.writeVariableBinding(id, instance.id)
16741669
}
16751670
else -> {
16761671
logger.warnElement(Severity.ErrorSevere, "Unrecognised IrExpression: " + e.javaClass, e)

java/ql/test/kotlin/library-tests/controlflow/basic/bbStmts.expected

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@
6060
| Test.kt:18:3:18:3 | <Expr>; | 20 | Test.kt:30:7:30:12 | ... == ... |
6161
| Test.kt:21:3:24:9 | ... -> ... | 0 | Test.kt:21:3:24:9 | ... -> ... |
6262
| Test.kt:21:3:24:9 | ... -> ... | 1 | Test.kt:21:3:24:9 | true |
63-
| Test.kt:21:3:24:9 | ... -> ... | 2 | Test.kt:24:4:24:9 | return ... |
63+
| Test.kt:21:3:24:9 | ... -> ... | 2 | Test.kt:24:4:24:9 | INSTANCE |
64+
| Test.kt:21:3:24:9 | ... -> ... | 3 | Test.kt:24:4:24:9 | return ... |
6465
| Test.kt:30:15:33:3 | { ... } | 0 | Test.kt:30:15:33:3 | { ... } |
6566
| Test.kt:30:15:33:3 | { ... } | 1 | Test.kt:31:4:31:4 | <Expr>; |
6667
| Test.kt:30:15:33:3 | { ... } | 2 | Test.kt:31:8:31:9 | 60 |
@@ -101,5 +102,6 @@
101102
| Test.kt:43:3:43:3 | <Expr>; | 6 | Test.kt:77:3:77:3 | <Expr>; |
102103
| Test.kt:43:3:43:3 | <Expr>; | 7 | Test.kt:77:7:77:8 | 40 |
103104
| Test.kt:43:3:43:3 | <Expr>; | 8 | Test.kt:77:3:77:3 | ...=... |
104-
| Test.kt:43:3:43:3 | <Expr>; | 9 | Test.kt:78:3:78:8 | return ... |
105-
| Test.kt:43:3:43:3 | <Expr>; | 10 | Test.kt:4:2:79:2 | test |
105+
| Test.kt:43:3:43:3 | <Expr>; | 9 | Test.kt:78:3:78:8 | INSTANCE |
106+
| Test.kt:43:3:43:3 | <Expr>; | 10 | Test.kt:78:3:78:8 | return ... |
107+
| Test.kt:43:3:43:3 | <Expr>; | 11 | Test.kt:4:2:79:2 | test |

java/ql/test/kotlin/library-tests/controlflow/basic/getASuccessor.expected

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,15 @@
5454
| Test.kt:21:3:24:9 | ... -> ... | WhenBranch | Test.kt:21:3:24:9 | true | BooleanLiteral |
5555
| Test.kt:21:3:24:9 | ... -> ... | WhenBranch | Test.kt:21:6:21:6 | x | VarAccess |
5656
| Test.kt:21:3:24:9 | <Expr>; | ExprStmt | Test.kt:21:3:24:9 | when ... | WhenExpr |
57-
| Test.kt:21:3:24:9 | true | BooleanLiteral | Test.kt:24:4:24:9 | return ... | ReturnStmt |
57+
| Test.kt:21:3:24:9 | true | BooleanLiteral | Test.kt:24:4:24:9 | INSTANCE | VarAccess |
5858
| Test.kt:21:3:24:9 | when ... | WhenExpr | Test.kt:21:3:24:9 | ... -> ... | WhenBranch |
5959
| Test.kt:21:6:21:6 | x | VarAccess | Test.kt:21:10:21:10 | 0 | IntegerLiteral |
6060
| Test.kt:21:6:21:10 | ... < ... | LTExpr | Test.kt:22:4:22:4 | <Expr>; | ExprStmt |
6161
| Test.kt:21:10:21:10 | 0 | IntegerLiteral | Test.kt:21:6:21:10 | ... < ... | LTExpr |
6262
| Test.kt:22:4:22:4 | ...=... | AssignExpr | Test.kt:27:3:27:3 | <Expr>; | ExprStmt |
6363
| Test.kt:22:4:22:4 | <Expr>; | ExprStmt | Test.kt:22:8:22:9 | 40 | LongLiteral |
6464
| Test.kt:22:8:22:9 | 40 | LongLiteral | Test.kt:22:4:22:4 | ...=... | AssignExpr |
65+
| Test.kt:24:4:24:9 | INSTANCE | VarAccess | Test.kt:24:4:24:9 | return ... | ReturnStmt |
6566
| Test.kt:24:4:24:9 | return ... | ReturnStmt | file://:0:0:0:0 | <none> | <none> |
6667
| Test.kt:27:3:27:3 | ...=... | AssignExpr | Test.kt:30:3:33:3 | <Expr>; | ExprStmt |
6768
| Test.kt:27:3:27:3 | <Expr>; | ExprStmt | Test.kt:27:7:27:8 | 10 | IntegerLiteral |
@@ -110,7 +111,8 @@
110111
| Test.kt:73:3:73:3 | ...=... | AssignExpr | Test.kt:77:3:77:3 | <Expr>; | ExprStmt |
111112
| Test.kt:73:3:73:3 | <Expr>; | ExprStmt | Test.kt:73:7:73:8 | 50 | IntegerLiteral |
112113
| Test.kt:73:7:73:8 | 50 | IntegerLiteral | Test.kt:73:3:73:3 | ...=... | AssignExpr |
113-
| Test.kt:77:3:77:3 | ...=... | AssignExpr | Test.kt:78:3:78:8 | return ... | ReturnStmt |
114+
| Test.kt:77:3:77:3 | ...=... | AssignExpr | Test.kt:78:3:78:8 | INSTANCE | VarAccess |
114115
| Test.kt:77:3:77:3 | <Expr>; | ExprStmt | Test.kt:77:7:77:8 | 40 | IntegerLiteral |
115116
| Test.kt:77:7:77:8 | 40 | IntegerLiteral | Test.kt:77:3:77:3 | ...=... | AssignExpr |
117+
| Test.kt:78:3:78:8 | INSTANCE | VarAccess | Test.kt:78:3:78:8 | return ... | ReturnStmt |
116118
| Test.kt:78:3:78:8 | return ... | ReturnStmt | Test.kt:4:2:79:2 | test | Method |

0 commit comments

Comments
 (0)