diff --git a/java/kotlin-extractor/src/main/kotlin/KotlinFileExtractor.kt b/java/kotlin-extractor/src/main/kotlin/KotlinFileExtractor.kt index 8cb27040881..320cae7ff09 100644 --- a/java/kotlin-extractor/src/main/kotlin/KotlinFileExtractor.kt +++ b/java/kotlin-extractor/src/main/kotlin/KotlinFileExtractor.kt @@ -1439,7 +1439,7 @@ open class KotlinFileExtractor( return extractValueParameter( id, substitutedType, - vp.name.asString(), + getConvergedValueParameterName(vp), location, parent, idx, @@ -3168,6 +3168,36 @@ open class KotlinFileExtractor( return tw.getLocation(keyword.startOffset, vp.endOffset) } + /** + * Returns the name to record for a value parameter, converging the two frontends where they + * disagree. + * + * A property's synthetic setter has a single implicit value parameter. The K2 frontend names + * it ``; the K1 frontend does the same for a + * member property's setter but names a *delegated* property's setter parameter `value`. That + * parameter is always compiler-synthesised (a delegated-property accessor carries no + * source-written parameters), so renaming it can never affect a user-written `value` parameter + * (for example the `value` parameter of a hand-written `ReadWriteProperty.setValue`, whose + * function has origin `DEFINED`). We therefore converge the delegated-setter parameter onto the + * canonical `` name (the `SpecialNames.IMPLICIT_SETTER_PARAMETER` constant is not present + * in every supported compiler version, so the literal is used directly). + * + * The rename is guarded on the K1 source name `value` so it targets *only* the setter value + * parameter: a delegated accessor's other parameters are receivers (`` for an extension + * property, `` for a member property), which must keep their names. Under K2 + * the setter parameter is already `` and the receivers are ``, so none match and + * the canonical K2 output is left untouched. + */ + private fun getConvergedValueParameterName(vp: IrValueParameter): String { + if ( + (vp.parent as? IrFunction)?.origin == IrDeclarationOrigin.DELEGATED_PROPERTY_ACCESSOR && + vp.name.asString() == "value" + ) { + return "" + } + return vp.name.asString() + } + /** * Returns the PSI-based location for a *synthesised* value parameter that has no source * token of its own, matching the span the K2 frontend emits natively, or null to leave the diff --git a/java/ql/test-kotlin1/library-tests/exprs/PrintAst.expected b/java/ql/test-kotlin1/library-tests/exprs/PrintAst.expected index 45bfea8c128..d9d2100a60e 100644 --- a/java/ql/test-kotlin1/library-tests/exprs/PrintAst.expected +++ b/java/ql/test-kotlin1/library-tests/exprs/PrintAst.expected @@ -294,7 +294,7 @@ delegatedProperties.kt: # 19| 2: [Method] # 19| 3: [TypeAccess] Unit #-----| 4: (Parameters) -# 19| 0: [Parameter] value +# 19| 0: [Parameter] # 19| 0: [TypeAccess] int # 19| 5: [BlockStmt] { ... } # 19| 0: [ReturnStmt] return ... @@ -328,7 +328,7 @@ delegatedProperties.kt: # 19| 0: [VarAccess] a0 # 19| -3: [TypeAccess] KMutableProperty0 # 19| 0: [TypeAccess] Integer -# 19| 2: [VarAccess] value +# 19| 2: [VarAccess] # 20| 1: [ExprStmt] ; # 20| 0: [MethodCall] println(...) # 20| -1: [TypeAccess] ConsoleKt @@ -538,7 +538,7 @@ delegatedProperties.kt: # 34| 2: [Method] # 34| 3: [TypeAccess] Unit #-----| 4: (Parameters) -# 34| 0: [Parameter] value +# 34| 0: [Parameter] # 34| 0: [TypeAccess] int # 34| 5: [BlockStmt] { ... } # 34| 0: [ReturnStmt] return ... @@ -572,7 +572,7 @@ delegatedProperties.kt: # 34| 0: [VarAccess] a0 # 34| -3: [TypeAccess] KMutableProperty0 # 34| 0: [TypeAccess] Integer -# 34| 2: [VarAccess] value +# 34| 2: [VarAccess] # 36| 7: [ExprStmt] ; # 36| 0: [MethodCall] println(...) # 36| -1: [TypeAccess] ConsoleKt @@ -1848,7 +1848,7 @@ delegatedProperties.kt: # 82| 2: [Method] # 82| 3: [TypeAccess] Unit #-----| 4: (Parameters) -# 82| 0: [Parameter] value +# 82| 0: [Parameter] # 82| 0: [TypeAccess] int # 82| 5: [BlockStmt] { ... } # 82| 0: [ReturnStmt] return ... @@ -1884,7 +1884,7 @@ delegatedProperties.kt: # 82| 0: [VarAccess] a0 # 82| -3: [TypeAccess] KMutableProperty0 # 82| 0: [TypeAccess] Integer -# 82| 3: [VarAccess] value +# 82| 3: [VarAccess] # 83| 1: [ExprStmt] ; # 83| 0: [MethodCall] fn(...) # 83| -1: [ThisAccess] this diff --git a/java/ql/test-kotlin1/library-tests/exprs/exprs.expected b/java/ql/test-kotlin1/library-tests/exprs/exprs.expected index 4a69ab873a0..7b5c952d6f3 100644 --- a/java/ql/test-kotlin1/library-tests/exprs/exprs.expected +++ b/java/ql/test-kotlin1/library-tests/exprs/exprs.expected @@ -58,6 +58,7 @@ | delegatedProperties.kt:19:34:19:51 | ...::... | delegatedProperties.kt:19:9:19:51 | | PropertyRefExpr | | delegatedProperties.kt:19:34:19:51 | (...) | delegatedProperties.kt:19:34:19:51 | get | MethodCall | | delegatedProperties.kt:19:34:19:51 | (...) | delegatedProperties.kt:19:34:19:51 | get | MethodCall | +| delegatedProperties.kt:19:34:19:51 | | delegatedProperties.kt:19:9:19:51 | | VarAccess | | delegatedProperties.kt:19:34:19:51 | (...) | delegatedProperties.kt:19:34:19:51 | set | MethodCall | | delegatedProperties.kt:19:34:19:51 | (...) | delegatedProperties.kt:19:34:19:51 | set | MethodCall | | delegatedProperties.kt:19:34:19:51 | Integer | delegatedProperties.kt:19:9:19:51 | | TypeAccess | @@ -82,7 +83,6 @@ | delegatedProperties.kt:19:34:19:51 | setValue(...) | delegatedProperties.kt:19:9:19:51 | | MethodCall | | delegatedProperties.kt:19:34:19:51 | this | delegatedProperties.kt:19:34:19:51 | invoke | ThisAccess | | delegatedProperties.kt:19:34:19:51 | this | delegatedProperties.kt:19:34:19:51 | invoke | ThisAccess | -| delegatedProperties.kt:19:34:19:51 | value | delegatedProperties.kt:19:9:19:51 | | VarAccess | | delegatedProperties.kt:19:34:19:51 | varResource1$delegate | delegatedProperties.kt:19:9:19:51 | | VarAccess | | delegatedProperties.kt:19:34:19:51 | varResource1$delegate | delegatedProperties.kt:19:9:19:51 | | VarAccess | | delegatedProperties.kt:20:9:20:29 | ConsoleKt | delegatedProperties.kt:18:5:40:5 | fn | TypeAccess | @@ -166,6 +166,7 @@ | delegatedProperties.kt:34:31:34:48 | ...::... | delegatedProperties.kt:34:9:34:48 | | PropertyRefExpr | | delegatedProperties.kt:34:31:34:48 | (...) | delegatedProperties.kt:34:31:34:48 | get | MethodCall | | delegatedProperties.kt:34:31:34:48 | (...) | delegatedProperties.kt:34:31:34:48 | get | MethodCall | +| delegatedProperties.kt:34:31:34:48 | | delegatedProperties.kt:34:9:34:48 | | VarAccess | | delegatedProperties.kt:34:31:34:48 | (...) | delegatedProperties.kt:34:31:34:48 | set | MethodCall | | delegatedProperties.kt:34:31:34:48 | (...) | delegatedProperties.kt:34:31:34:48 | set | MethodCall | | delegatedProperties.kt:34:31:34:48 | Integer | delegatedProperties.kt:34:9:34:48 | | TypeAccess | @@ -193,7 +194,6 @@ | delegatedProperties.kt:34:31:34:48 | setValue(...) | delegatedProperties.kt:34:9:34:48 | | MethodCall | | delegatedProperties.kt:34:31:34:48 | this | delegatedProperties.kt:34:31:34:48 | invoke | ThisAccess | | delegatedProperties.kt:34:31:34:48 | this | delegatedProperties.kt:34:31:34:48 | invoke | ThisAccess | -| delegatedProperties.kt:34:31:34:48 | value | delegatedProperties.kt:34:9:34:48 | | VarAccess | | delegatedProperties.kt:36:9:36:29 | ConsoleKt | delegatedProperties.kt:18:5:40:5 | fn | TypeAccess | | delegatedProperties.kt:36:9:36:29 | println(...) | delegatedProperties.kt:18:5:40:5 | fn | MethodCall | | delegatedProperties.kt:36:17:36:28 | getVarResource0(...) | delegatedProperties.kt:18:5:40:5 | fn | MethodCall | @@ -777,6 +777,7 @@ | delegatedProperties.kt:82:40:82:54 | | delegatedProperties.kt:82:40:82:54 | | VarAccess | | delegatedProperties.kt:82:40:82:54 | (...) | delegatedProperties.kt:82:40:82:54 | get | MethodCall | | delegatedProperties.kt:82:40:82:54 | (...) | delegatedProperties.kt:82:40:82:54 | get | MethodCall | +| delegatedProperties.kt:82:40:82:54 | | delegatedProperties.kt:82:9:82:54 | | VarAccess | | delegatedProperties.kt:82:40:82:54 | (...) | delegatedProperties.kt:82:40:82:54 | set | MethodCall | | delegatedProperties.kt:82:40:82:54 | (...) | delegatedProperties.kt:82:40:82:54 | set | MethodCall | | delegatedProperties.kt:82:40:82:54 | Integer | delegatedProperties.kt:81:5:84:5 | fn | TypeAccess | @@ -819,7 +820,6 @@ | delegatedProperties.kt:82:40:82:54 | this. | delegatedProperties.kt:82:40:82:54 | | VarAccess | | delegatedProperties.kt:82:40:82:54 | this. | delegatedProperties.kt:82:40:82:54 | get | VarAccess | | delegatedProperties.kt:82:40:82:54 | this. | delegatedProperties.kt:82:40:82:54 | set | VarAccess | -| delegatedProperties.kt:82:40:82:54 | value | delegatedProperties.kt:82:9:82:54 | | VarAccess | | delegatedProperties.kt:83:9:83:12 | fn(...) | delegatedProperties.kt:81:5:84:5 | fn | MethodCall | | delegatedProperties.kt:83:9:83:12 | this | delegatedProperties.kt:81:5:84:5 | fn | ThisAccess | | delegatedProperties.kt:87:1:87:46 | MyClass | file://:0:0:0:0 | | TypeAccess |