Skip to content

Commit c7c2d2d

Browse files
kotlin-extractor: fix NotNullExpr start offset to span from operand
In K1 mode, the IrCall node for the !! operator stores startOffset at the '!' character rather than at the start of the operand. This means that x!! was previously reported as spanning from '!' to the end of the expression, omitting the operand from the location. Fix this by computing the NotNullExpr location from the value argument's startOffset (the operand) to c.endOffset. This matches the K2 behaviour where the IrCall.startOffset already points at the operand. The fix guards against invalid (< 0) offsets on either side and falls back to the default IrCall location in those cases. Updated expected files in test-kotlin1: - exprs/unaryOp.expected: !! locations now start at operand column - exprs/exprs.expected: same (NotNullExpr entries corrected) - exprs/binop.expected: !! child locations now correct (parent binop location for s!!.plus(5) still differs due to a separate K1 IR limitation where the enclosing call inherits the wrong receiver offset) - controlflow/basic/bbStmts.expected: CFG references to !! now use the improved location - controlflow/basic/getASuccessor.expected: same Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent b766d5b commit c7c2d2d

6 files changed

Lines changed: 29 additions & 23 deletions

File tree

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3084,9 +3084,10 @@ open class KotlinFileExtractor(
30843084
id: Label<out DbExpr>,
30853085
c: IrCall,
30863086
callable: Label<out DbCallable>,
3087-
enclosingStmt: Label<out DbStmt>
3087+
enclosingStmt: Label<out DbStmt>,
3088+
customLocId: Label<DbLocation>? = null
30883089
) {
3089-
val locId = tw.getLocation(c)
3090+
val locId = customLocId ?: tw.getLocation(c)
30903091
extractExprContext(id, locId, callable, enclosingStmt)
30913092

30923093
val dr = c.dispatchReceiver
@@ -4584,7 +4585,12 @@ open class KotlinFileExtractor(
45844585
val type = useType(c.type)
45854586
tw.writeExprs_notnullexpr(id, type.javaResult.id, parent, idx)
45864587
tw.writeExprsKotlinType(id, type.kotlinResult.id)
4587-
unaryOp(id, c, callable, enclosingStmt)
4588+
// In K1 mode the IrCall.startOffset for !! points to the '!' character rather
4589+
// than the start of the operand. Use the operand's startOffset instead so that
4590+
// the NotNullExpr spans from the operand to the end of '!!'.
4591+
val operandStart = c.codeQlGetValueArgument(0)?.startOffset?.takeIf { it >= 0 }
4592+
val notNullLocId = if (operandStart != null && c.endOffset >= 0) tw.getLocation(operandStart, c.endOffset) else null
4593+
unaryOp(id, c, callable, enclosingStmt, notNullLocId)
45884594
}
45894595
isBuiltinCallInternal(c, "THROW_CCE") -> {
45904596
// TODO

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -251,18 +251,18 @@
251251
| Test.kt:91:1:98:1 | Entry | 3 | Test.kt:92:6:95:2 | { ... } |
252252
| Test.kt:91:1:98:1 | Entry | 4 | Test.kt:93:7:93:7 | var ...; |
253253
| Test.kt:91:1:98:1 | Entry | 5 | Test.kt:93:7:93:7 | Before x |
254-
| Test.kt:91:1:98:1 | Entry | 6 | Test.kt:93:12:93:13 | Before ...!! |
254+
| Test.kt:91:1:98:1 | Entry | 6 | Test.kt:93:11:93:13 | Before ...!! |
255255
| Test.kt:91:1:98:1 | Entry | 7 | Test.kt:93:11:93:11 | o |
256-
| Test.kt:91:1:98:1 | Entry | 8 | Test.kt:93:12:93:13 | ...!! |
256+
| Test.kt:91:1:98:1 | Entry | 8 | Test.kt:93:11:93:13 | ...!! |
257257
| Test.kt:91:1:98:1 | Exit | 0 | Test.kt:91:1:98:1 | Exit |
258258
| Test.kt:91:1:98:1 | Normal Exit | 0 | Test.kt:91:1:98:1 | Normal Exit |
259-
| Test.kt:93:12:93:13 | After ...!! | 0 | Test.kt:93:12:93:13 | After ...!! |
260-
| Test.kt:93:12:93:13 | After ...!! | 1 | Test.kt:93:7:93:7 | x |
261-
| Test.kt:93:12:93:13 | After ...!! | 2 | Test.kt:93:7:93:7 | After x |
262-
| Test.kt:93:12:93:13 | After ...!! | 3 | Test.kt:93:7:93:7 | After var ...; |
263-
| Test.kt:93:12:93:13 | After ...!! | 4 | Test.kt:94:3:94:10 | Before return ... |
264-
| Test.kt:93:12:93:13 | After ...!! | 5 | Test.kt:94:10:94:10 | 1 |
265-
| Test.kt:93:12:93:13 | After ...!! | 6 | Test.kt:94:3:94:10 | return ... |
259+
| Test.kt:93:11:93:13 | After ...!! | 0 | Test.kt:93:11:93:13 | After ...!! |
260+
| Test.kt:93:11:93:13 | After ...!! | 1 | Test.kt:93:7:93:7 | x |
261+
| Test.kt:93:11:93:13 | After ...!! | 2 | Test.kt:93:7:93:7 | After x |
262+
| Test.kt:93:11:93:13 | After ...!! | 3 | Test.kt:93:7:93:7 | After var ...; |
263+
| Test.kt:93:11:93:13 | After ...!! | 4 | Test.kt:94:3:94:10 | Before return ... |
264+
| Test.kt:93:11:93:13 | After ...!! | 5 | Test.kt:94:10:94:10 | 1 |
265+
| Test.kt:93:11:93:13 | After ...!! | 6 | Test.kt:94:3:94:10 | return ... |
266266
| Test.kt:95:4:97:2 | catch (...) | 0 | Test.kt:95:4:97:2 | catch (...) |
267267
| Test.kt:95:4:97:2 | catch (...) | 1 | Test.kt:95:11:95:33 | e |
268268
| Test.kt:95:11:95:33 | After e [match] | 0 | Test.kt:95:11:95:33 | After e [match] |

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,9 @@
150150
| Test.kt:92:6:95:2 | { ... } | BlockStmt | Test.kt:93:7:93:7 | var ...; | LocalVariableDeclStmt |
151151
| Test.kt:93:7:93:7 | var ...; | LocalVariableDeclStmt | Test.kt:93:11:93:11 | o | VarAccess |
152152
| Test.kt:93:7:93:7 | x | LocalVariableDeclExpr | Test.kt:94:10:94:10 | 1 | IntegerLiteral |
153-
| Test.kt:93:11:93:11 | o | VarAccess | Test.kt:93:12:93:13 | ...!! | NotNullExpr |
154-
| Test.kt:93:12:93:13 | ...!! | NotNullExpr | Test.kt:93:7:93:7 | x | LocalVariableDeclExpr |
155-
| Test.kt:93:12:93:13 | ...!! | NotNullExpr | Test.kt:95:4:97:2 | catch (...) | CatchClause |
153+
| Test.kt:93:11:93:11 | o | VarAccess | Test.kt:93:11:93:13 | ...!! | NotNullExpr |
154+
| Test.kt:93:11:93:13 | ...!! | NotNullExpr | Test.kt:93:7:93:7 | x | LocalVariableDeclExpr |
155+
| Test.kt:93:11:93:13 | ...!! | NotNullExpr | Test.kt:95:4:97:2 | catch (...) | CatchClause |
156156
| Test.kt:94:3:94:10 | return ... | ReturnStmt | Test.kt:91:1:98:1 | Normal Exit | Method |
157157
| Test.kt:94:10:94:10 | 1 | IntegerLiteral | Test.kt:94:3:94:10 | return ... | ReturnStmt |
158158
| Test.kt:95:4:97:2 | catch (...) | CatchClause | Test.kt:95:11:95:33 | e | LocalVariableDeclExpr |

java/ql/test-kotlin1/library-tests/exprs/binop.expected

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@
9696
| exprs.kt:141:12:141:20 | ... + ... | exprs.kt:141:12:141:14 | 123 | exprs.kt:141:18:141:20 | 456 |
9797
| exprs.kt:167:8:167:16 | ... (value not-equals) ... | exprs.kt:167:8:167:8 | r | exprs.kt:167:13:167:16 | null |
9898
| exprs.kt:196:31:196:37 | ... + ... | exprs.kt:196:31:196:32 | getA1(...) | exprs.kt:196:36:196:37 | a2 |
99-
| exprs.kt:211:20:211:29 | ... + ... | exprs.kt:211:20:211:21 | ...!! | exprs.kt:211:28:211:28 | 5 |
100-
| exprs.kt:212:19:212:25 | ... + ... | exprs.kt:212:20:212:21 | ...!! | exprs.kt:212:25:212:25 | 5 |
99+
| exprs.kt:211:20:211:29 | ... + ... | exprs.kt:211:19:211:21 | ...!! | exprs.kt:211:28:211:28 | 5 |
100+
| exprs.kt:212:19:212:25 | ... + ... | exprs.kt:212:19:212:21 | ...!! | exprs.kt:212:25:212:25 | 5 |
101101
| exprs.kt:230:12:230:47 | ... (value equals) ... | exprs.kt:230:12:230:27 | notNullPrimitive | exprs.kt:230:32:230:47 | notNullPrimitive |
102102
| exprs.kt:231:12:231:48 | ... (value equals) ... | exprs.kt:231:12:231:27 | notNullPrimitive | exprs.kt:231:32:231:48 | nullablePrimitive |
103103
| exprs.kt:232:12:232:49 | ... (value equals) ... | exprs.kt:232:12:232:28 | nullablePrimitive | exprs.kt:232:33:232:49 | nullablePrimitive |

java/ql/test-kotlin1/library-tests/exprs/exprs.expected

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,7 +1572,7 @@
15721572
| exprs.kt:201:22:201:28 | Object | file://:0:0:0:0 | <none> | TypeAccess |
15731573
| exprs.kt:202:9:202:9 | y | exprs.kt:201:1:203:1 | notNullAssertion | LocalVariableDeclExpr |
15741574
| exprs.kt:202:18:202:18 | x | exprs.kt:201:1:203:1 | notNullAssertion | VarAccess |
1575-
| exprs.kt:202:19:202:20 | ...!! | exprs.kt:201:1:203:1 | notNullAssertion | NotNullExpr |
1575+
| exprs.kt:202:18:202:20 | ...!! | exprs.kt:201:1:203:1 | notNullAssertion | NotNullExpr |
15761576
| exprs.kt:206:5:217:5 | Unit | file://:0:0:0:0 | <none> | TypeAccess |
15771577
| exprs.kt:206:11:206:18 | Object | file://:0:0:0:0 | <none> | TypeAccess |
15781578
| exprs.kt:206:21:206:30 | String | file://:0:0:0:0 | <none> | TypeAccess |
@@ -1592,13 +1592,13 @@
15921592
| exprs.kt:210:23:210:23 | 5 | exprs.kt:206:5:217:5 | x | IntegerLiteral |
15931593
| exprs.kt:211:13:211:14 | b2 | exprs.kt:206:5:217:5 | x | LocalVariableDeclExpr |
15941594
| exprs.kt:211:19:211:19 | s | exprs.kt:206:5:217:5 | x | VarAccess |
1595-
| exprs.kt:211:20:211:21 | ...!! | exprs.kt:206:5:217:5 | x | NotNullExpr |
1595+
| exprs.kt:211:19:211:21 | ...!! | exprs.kt:206:5:217:5 | x | NotNullExpr |
15961596
| exprs.kt:211:20:211:29 | ... + ... | exprs.kt:206:5:217:5 | x | AddExpr |
15971597
| exprs.kt:211:28:211:28 | 5 | exprs.kt:206:5:217:5 | x | IntegerLiteral |
15981598
| exprs.kt:212:13:212:14 | b3 | exprs.kt:206:5:217:5 | x | LocalVariableDeclExpr |
15991599
| exprs.kt:212:19:212:19 | s | exprs.kt:206:5:217:5 | x | VarAccess |
1600+
| exprs.kt:212:19:212:21 | ...!! | exprs.kt:206:5:217:5 | x | NotNullExpr |
16001601
| exprs.kt:212:19:212:25 | ... + ... | exprs.kt:206:5:217:5 | x | AddExpr |
1601-
| exprs.kt:212:20:212:21 | ...!! | exprs.kt:206:5:217:5 | x | NotNullExpr |
16021602
| exprs.kt:212:25:212:25 | 5 | exprs.kt:206:5:217:5 | x | IntegerLiteral |
16031603
| exprs.kt:213:13:213:14 | c0 | exprs.kt:206:5:217:5 | x | LocalVariableDeclExpr |
16041604
| exprs.kt:213:18:213:36 | Color | exprs.kt:206:5:217:5 | x | TypeAccess |

java/ql/test-kotlin1/library-tests/exprs/unaryOp.expected

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
| exprs.kt:32:15:32:26 | !... | exprs.kt:32:15:32:26 | contains(...) |
33
| exprs.kt:79:15:79:22 | ~... | exprs.kt:79:15:79:16 | lx |
44
| exprs.kt:121:14:121:16 | !... | exprs.kt:121:15:121:16 | b1 |
5-
| exprs.kt:202:19:202:20 | ...!! | exprs.kt:202:18:202:18 | x |
6-
| exprs.kt:211:20:211:21 | ...!! | exprs.kt:211:19:211:19 | s |
7-
| exprs.kt:212:20:212:21 | ...!! | exprs.kt:212:19:212:19 | s |
5+
| exprs.kt:202:18:202:20 | ...!! | exprs.kt:202:18:202:18 | x |
6+
| exprs.kt:211:19:211:21 | ...!! | exprs.kt:211:19:211:19 | s |
7+
| exprs.kt:212:19:212:21 | ...!! | exprs.kt:212:19:212:19 | s |
88
| exprs.kt:286:5:286:6 | -... | exprs.kt:286:6:286:6 | i |
99
| exprs.kt:287:5:287:6 | +... | exprs.kt:287:6:287:6 | i |
1010
| exprs.kt:288:5:288:6 | -... | exprs.kt:288:6:288:6 | d |

0 commit comments

Comments
 (0)