Skip to content

Commit 826bbdf

Browse files
committed
Kotlin: Fix vararg extraction outside of method call
1 parent cb3c53d commit 826bbdf

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3056,7 +3056,13 @@ open class KotlinFileExtractor(
30563056
extractTypeOperatorCall(e, callable, exprParent.parent, exprParent.idx, exprParent.enclosingStmt)
30573057
}
30583058
is IrVararg -> {
3059-
logger.errorElement("Unexpected IrVararg", e)
3059+
if (e.elements.size != 1 || e.elements[0] !is IrSpreadElement) {
3060+
logger.errorElement("Unexpected IrVararg", e)
3061+
return
3062+
}
3063+
// There are lowered IR cases when the vararg expression is not within a call, such as
3064+
// val temp0 = [*expr]
3065+
extractExpression((e.elements[0] as IrSpreadElement).expression, callable, parent)
30603066
}
30613067
is IrGetObjectValue -> {
30623068
// For `object MyObject { ... }`, the .class has an

java/ql/test/kotlin/library-tests/vararg/args.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
diag
2-
| test.kt:55:15:55:35 | Unexpected IrVararg |
32
varargsParams
43
| test.kt:8:15:8:28 | xs | file://:0:0:0:0 | int[] |
54
| test.kt:12:26:12:39 | xs | file://:0:0:0:0 | int[] |
@@ -84,3 +83,4 @@ implicitVarargsArguments
8483
| test.kt:45:5:45:39 | new HasVarargConstructor(...) | 1 | test.kt:45:34:45:38 | array |
8584
| test.kt:55:13:55:43 | new X(...) | 0 | test.kt:55:42:55:42 | 1 |
8685
| test.kt:55:13:55:43 | new X(...) | 1 | test.kt:55:15:55:35 | tmp0_s |
86+
| test.kt:55:22:55:35 | toTypedArray(...) | 0 | test.kt:55:19:55:20 | sl |

0 commit comments

Comments
 (0)