Add test case for local variable in anonymous init

Also fix another instance of the same issue in extractLocalTypeDeclStmt
This commit is contained in:
Tony Torralba
2022-03-23 17:19:50 +01:00
committed by Ian Lynagh
parent 1926bef050
commit f8ad93a530
9 changed files with 59 additions and 1 deletions

View File

@@ -328,8 +328,9 @@ open class KotlinFileExtractor(
}
private fun extractLocalTypeDeclStmt(c: IrClass, callable: Label<out DbCallable>, parent: Label<out DbStmtparent>, idx: Int) {
val extractStaticInit = c.declarations.none { it is IrAnonymousInitializer }
@Suppress("UNCHECKED_CAST")
val id = extractClassSource(c, true, true) as Label<out DbClass>
val id = extractClassSource(c, true, extractStaticInit) as Label<out DbClass>
extractLocalTypeDeclStmt(id, c, callable, parent, idx)
}

View File

@@ -662,6 +662,45 @@ local_anonymous.kt:
# 29| 1: [ExprStmt] <Expr>;
# 29| 0: [ClassInstanceExpr] new (...)
# 29| -3: [TypeAccess] Object
# 38| 2: [Interface] Interface2
# 39| 3: [Class] Class2
# 39| 1: [Constructor] Class2
# 39| 5: [BlockStmt] { ... }
# 39| 0: [SuperConstructorInvocationStmt] super(...)
# 39| 1: [BlockStmt] { ... }
# 40| 0: [ExprStmt] <Expr>;
# 40| 0: [KtInitializerAssignExpr] ...=...
# 40| 0: [VarAccess] i
# 40| 2: [Method] getI
# 40| 5: [BlockStmt] { ... }
# 40| 0: [ReturnStmt] return ...
# 40| 0: [VarAccess] this.i
# 40| -1: [ThisAccess] this
# 40| 2: [Method] setI
#-----| 4: (Parameters)
# 40| 0: [Parameter] <set-?>
# 40| 5: [BlockStmt] { ... }
# 40| 0: [ExprStmt] <Expr>;
# 40| 0: [AssignExpr] ...=...
# 40| 0: [VarAccess] this.i
# 40| -1: [ThisAccess] this
# 40| 1: [VarAccess] <set-?>
# 40| 2: [FieldDeclaration] Interface2 i;
# 40| -1: [TypeAccess] Interface2
# 40| 0: [StmtExpr] <Stmt>
# 40| 0: [BlockStmt] { ... }
# 40| 0: [LocalTypeDeclStmt] class ...
# 40| 0: [AnonymousClass,LocalClass] new Interface2(...) { ... }
# 40| 1: [Constructor]
# 40| 5: [BlockStmt] { ... }
# 40| 0: [SuperConstructorInvocationStmt] super(...)
# 40| 1: [BlockStmt] { ... }
# 42| 0: [LocalVariableDeclStmt] var ...;
# 42| 1: [LocalVariableDeclExpr] answer
# 42| 0: [StringLiteral] 42
# 40| 1: [ExprStmt] <Expr>;
# 40| 0: [ClassInstanceExpr] new (...)
# 40| -3: [TypeAccess] Interface2
superChain.kt:
# 0| [CompilationUnit] superChain
# 1| 1: [Class,GenericType,ParameterizedType] SuperChain1

View File

@@ -9,3 +9,4 @@
| generic_anonymous.kt:3:19:5:3 | new Object(...) { ... } | generic_anonymous.kt:3:19:5:3 | new (...) | | generic_anonymous.kt:3:19:5:3 | Object | generic_anonymous.kt:3:19:5:3 | class ... |
| local_anonymous.kt:5:16:7:9 | new Object(...) { ... } | local_anonymous.kt:5:16:7:9 | new (...) | | local_anonymous.kt:5:16:7:9 | Object | local_anonymous.kt:5:16:7:9 | class ... |
| local_anonymous.kt:29:31:35:5 | new Object(...) { ... } | local_anonymous.kt:29:31:35:5 | new (...) | | local_anonymous.kt:29:31:35:5 | Object | local_anonymous.kt:29:31:35:5 | class ... |
| local_anonymous.kt:40:14:44:5 | new Interface2(...) { ... } | local_anonymous.kt:40:14:44:5 | new (...) | | local_anonymous.kt:40:14:44:5 | Interface2 | local_anonymous.kt:40:14:44:5 | class ... |

View File

@@ -45,6 +45,8 @@
| local_anonymous.kt:21:21:21:31 | new Function1<Class1,Unit>(...) { ... } | <anonymous class> | final, private |
| local_anonymous.kt:25:9:25:27 | LocalClass | LocalAnonymous.Class1$LocalClass | final, private |
| local_anonymous.kt:29:31:35:5 | new Object(...) { ... } | <anonymous class> | final, private |
| local_anonymous.kt:39:1:45:1 | Class2 | LocalAnonymous.Class2 | final, public |
| local_anonymous.kt:40:14:44:5 | new Interface2(...) { ... } | <anonymous class> | final, private |
| superChain.kt:1:1:1:33 | SuperChain1 | SuperChain1 | public |
| superChain.kt:2:1:2:60 | SuperChain2 | SuperChain2 | public |
| superChain.kt:3:1:3:60 | SuperChain3 | SuperChain3 | public |

View File

@@ -44,6 +44,8 @@ superCall
| local_anonymous.kt:21:21:21:31 | super(...) |
| local_anonymous.kt:25:9:25:27 | super(...) |
| local_anonymous.kt:29:31:35:5 | super(...) |
| local_anonymous.kt:39:1:45:1 | super(...) |
| local_anonymous.kt:40:14:44:5 | super(...) |
| superChain.kt:1:1:1:33 | super(...) |
| superChain.kt:2:33:2:57 | super(...) |
| superChain.kt:3:33:3:57 | super(...) |

View File

@@ -3,3 +3,4 @@
| classes.kt:59:1:59:23 | Interface1 |
| classes.kt:60:1:60:23 | Interface2 |
| classes.kt:61:1:61:26 | Interface3 |
| local_anonymous.kt:38:1:38:23 | Interface2 |

View File

@@ -1,6 +1,7 @@
anonymousObjects
| local_anonymous.kt:5:16:7:9 | new (...) | local_anonymous.kt:5:16:7:9 | new Object(...) { ... } | anonymous | local |
| local_anonymous.kt:29:31:35:5 | new (...) | local_anonymous.kt:29:31:35:5 | new Object(...) { ... } | anonymous | local |
| local_anonymous.kt:40:14:44:5 | new (...) | local_anonymous.kt:40:14:44:5 | new Interface2(...) { ... } | anonymous | local |
localFunctions
| local_anonymous.kt:11:9:11:24 | fnLocal | local_anonymous.kt:11:9:11:24 | | not anonymous | local |
lambdas

View File

@@ -34,3 +34,12 @@ class Class1 {
}
}
}
interface Interface2 {}
class Class2 {
var i = object: Interface2 {
init {
var answer: String = "42" // Local variable in anonymous class initializer
}
}
}

View File

@@ -58,6 +58,8 @@
| local_anonymous.kt:21:21:21:31 | new Function1<Class1,Unit>(...) { ... } | file://<external>/FunctionReference.class:0:0:0:0 | FunctionReference |
| local_anonymous.kt:25:9:25:27 | LocalClass | file://<external>/Object.class:0:0:0:0 | Object |
| local_anonymous.kt:29:31:35:5 | new Object(...) { ... } | file://<external>/Object.class:0:0:0:0 | Object |
| local_anonymous.kt:39:1:45:1 | Class2 | file://<external>/Object.class:0:0:0:0 | Object |
| local_anonymous.kt:40:14:44:5 | new Interface2(...) { ... } | local_anonymous.kt:38:1:38:23 | Interface2 |
| superChain.kt:1:1:1:33 | SuperChain1 | file://<external>/Object.class:0:0:0:0 | Object |
| superChain.kt:1:1:1:33 | SuperChain1<T3,String> | file://<external>/Object.class:0:0:0:0 | Object |
| superChain.kt:1:1:1:33 | SuperChain1<T5,String> | file://<external>/Object.class:0:0:0:0 | Object |