Kotlin: Fix handling of objects in external dependencies

This commit is contained in:
Ian Lynagh
2021-11-08 17:47:42 +00:00
parent b460c92c61
commit f726e6acf8
3 changed files with 17 additions and 18 deletions

View File

@@ -906,7 +906,7 @@ open class KotlinFileExtractor(
if(!c.isNonCompanionObject) {
logger.warn(Severity.ErrorSevere, "Using instance for non-object class")
}
val classId = useClassSource(c)
val classId = useClassInstance(c, listOf()).classLabel
val instanceName = "INSTANCE"
val instanceLabel = "@\"field;{$classId};$instanceName\""
val instanceId: Label<DbField> = tw.getLabelFor(instanceLabel)
@@ -1657,20 +1657,15 @@ open class KotlinFileExtractor(
// field that we are accessing here.
val exprParent = parent.expr(e, callable)
val c: IrClass = e.symbol.owner
// TODO: If this is enabled for Unit then it currently makes tests fail
if(c.name.asString() == "Unit") {
logger.warnElement(Severity.ErrorSevere, "Unit object not handled yet", e)
} else {
val instance = useObjectClassInstance(c)
val instance = useObjectClassInstance(c)
val id = tw.getFreshIdLabel<DbVaraccess>()
val type = useType(e.type)
val locId = tw.getLocation(e)
tw.writeExprs_varaccess(id, type.javaResult.id, type.kotlinResult.id, exprParent.parent, exprParent.idx)
tw.writeHasLocation(id, locId)
val id = tw.getFreshIdLabel<DbVaraccess>()
val type = useType(e.type)
val locId = tw.getLocation(e)
tw.writeExprs_varaccess(id, type.javaResult.id, type.kotlinResult.id, exprParent.parent, exprParent.idx)
tw.writeHasLocation(id, locId)
tw.writeVariableBinding(id, instance.id)
}
tw.writeVariableBinding(id, instance.id)
}
else -> {
logger.warnElement(Severity.ErrorSevere, "Unrecognised IrExpression: " + e.javaClass, e)

View File

@@ -60,7 +60,8 @@
| Test.kt:18:3:18:3 | <Expr>; | 20 | Test.kt:30:7:30:12 | ... == ... |
| Test.kt:21:3:24:9 | ... -> ... | 0 | Test.kt:21:3:24:9 | ... -> ... |
| Test.kt:21:3:24:9 | ... -> ... | 1 | Test.kt:21:3:24:9 | true |
| Test.kt:21:3:24:9 | ... -> ... | 2 | Test.kt:24:4:24:9 | return ... |
| Test.kt:21:3:24:9 | ... -> ... | 2 | Test.kt:24:4:24:9 | INSTANCE |
| Test.kt:21:3:24:9 | ... -> ... | 3 | Test.kt:24:4:24:9 | return ... |
| Test.kt:30:15:33:3 | { ... } | 0 | Test.kt:30:15:33:3 | { ... } |
| Test.kt:30:15:33:3 | { ... } | 1 | Test.kt:31:4:31:4 | <Expr>; |
| Test.kt:30:15:33:3 | { ... } | 2 | Test.kt:31:8:31:9 | 60 |
@@ -101,5 +102,6 @@
| Test.kt:43:3:43:3 | <Expr>; | 6 | Test.kt:77:3:77:3 | <Expr>; |
| Test.kt:43:3:43:3 | <Expr>; | 7 | Test.kt:77:7:77:8 | 40 |
| Test.kt:43:3:43:3 | <Expr>; | 8 | Test.kt:77:3:77:3 | ...=... |
| Test.kt:43:3:43:3 | <Expr>; | 9 | Test.kt:78:3:78:8 | return ... |
| Test.kt:43:3:43:3 | <Expr>; | 10 | Test.kt:4:2:79:2 | test |
| Test.kt:43:3:43:3 | <Expr>; | 9 | Test.kt:78:3:78:8 | INSTANCE |
| Test.kt:43:3:43:3 | <Expr>; | 10 | Test.kt:78:3:78:8 | return ... |
| Test.kt:43:3:43:3 | <Expr>; | 11 | Test.kt:4:2:79:2 | test |

View File

@@ -54,7 +54,7 @@
| Test.kt:21:3:24:9 | ... -> ... | WhenBranch | Test.kt:21:3:24:9 | true | BooleanLiteral |
| Test.kt:21:3:24:9 | ... -> ... | WhenBranch | Test.kt:21:6:21:6 | x | VarAccess |
| Test.kt:21:3:24:9 | <Expr>; | ExprStmt | Test.kt:21:3:24:9 | when ... | WhenExpr |
| Test.kt:21:3:24:9 | true | BooleanLiteral | Test.kt:24:4:24:9 | return ... | ReturnStmt |
| Test.kt:21:3:24:9 | true | BooleanLiteral | Test.kt:24:4:24:9 | INSTANCE | VarAccess |
| Test.kt:21:3:24:9 | when ... | WhenExpr | Test.kt:21:3:24:9 | ... -> ... | WhenBranch |
| Test.kt:21:6:21:6 | x | VarAccess | Test.kt:21:10:21:10 | 0 | IntegerLiteral |
| Test.kt:21:6:21:10 | ... < ... | LTExpr | Test.kt:22:4:22:4 | <Expr>; | ExprStmt |
@@ -62,6 +62,7 @@
| Test.kt:22:4:22:4 | ...=... | AssignExpr | Test.kt:27:3:27:3 | <Expr>; | ExprStmt |
| Test.kt:22:4:22:4 | <Expr>; | ExprStmt | Test.kt:22:8:22:9 | 40 | LongLiteral |
| Test.kt:22:8:22:9 | 40 | LongLiteral | Test.kt:22:4:22:4 | ...=... | AssignExpr |
| Test.kt:24:4:24:9 | INSTANCE | VarAccess | Test.kt:24:4:24:9 | return ... | ReturnStmt |
| Test.kt:24:4:24:9 | return ... | ReturnStmt | file://:0:0:0:0 | <none> | <none> |
| Test.kt:27:3:27:3 | ...=... | AssignExpr | Test.kt:30:3:33:3 | <Expr>; | ExprStmt |
| Test.kt:27:3:27:3 | <Expr>; | ExprStmt | Test.kt:27:7:27:8 | 10 | IntegerLiteral |
@@ -110,7 +111,8 @@
| Test.kt:73:3:73:3 | ...=... | AssignExpr | Test.kt:77:3:77:3 | <Expr>; | ExprStmt |
| Test.kt:73:3:73:3 | <Expr>; | ExprStmt | Test.kt:73:7:73:8 | 50 | IntegerLiteral |
| Test.kt:73:7:73:8 | 50 | IntegerLiteral | Test.kt:73:3:73:3 | ...=... | AssignExpr |
| Test.kt:77:3:77:3 | ...=... | AssignExpr | Test.kt:78:3:78:8 | return ... | ReturnStmt |
| Test.kt:77:3:77:3 | ...=... | AssignExpr | Test.kt:78:3:78:8 | INSTANCE | VarAccess |
| Test.kt:77:3:77:3 | <Expr>; | ExprStmt | Test.kt:77:7:77:8 | 40 | IntegerLiteral |
| Test.kt:77:7:77:8 | 40 | IntegerLiteral | Test.kt:77:3:77:3 | ...=... | AssignExpr |
| Test.kt:78:3:78:8 | INSTANCE | VarAccess | Test.kt:78:3:78:8 | return ... | ReturnStmt |
| Test.kt:78:3:78:8 | return ... | ReturnStmt | Test.kt:4:2:79:2 | test | Method |