Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 04daa7f

Browse files
tamasvajkigfoo
authored andcommitted
Revert "Kotlin: Fix extraction of dispatch and extension receivers"
1 parent cd84a6a commit 04daa7f

4 files changed

Lines changed: 11 additions & 14 deletions

File tree

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -683,17 +683,20 @@ open class KotlinFileExtractor(
683683
tw.writeStatementEnclosingExpr(id, enclosingStmt)
684684

685685
if (extractTypeArguments) {
686-
// type arguments at index -3, -4, ...
687-
extractTypeArguments(c, id, callable, enclosingStmt, -3, true)
686+
// type arguments at index -2, -3, ...
687+
extractTypeArguments(c, id, callable, enclosingStmt, -2, true)
688688
}
689689

690690
val dr = c.dispatchReceiver
691691
val er = c.extensionReceiver
692692
if (dr != null) {
693693
extractExpressionExpr(dr, callable, id, -1, enclosingStmt)
694-
}
695-
if (er != null) {
696-
extractExpressionExpr(er, callable, id, -2, enclosingStmt)
694+
695+
if (er != null && er != dr) {
696+
logger.warnElement(Severity.ErrorSevere, "Expected to only find extension receiver or dispatch receiver. Found both. Extracting dispatch receiver only", c)
697+
}
698+
} else if (er != null) {
699+
extractExpressionExpr(er, callable, id, -1, enclosingStmt)
697700
}
698701

699702
for(i in 0 until c.valueArgumentsCount) {
@@ -964,7 +967,7 @@ open class KotlinFileExtractor(
964967

965968
if (isBuiltinCallKotlin(c, "arrayOf")) {
966969
if (c.typeArgumentsCount == 1) {
967-
extractTypeArguments(c, id, callable, enclosingStmt, -1)
970+
extractTypeArguments(c, id, callable, enclosingStmt,-1)
968971
} else {
969972
logger.warnElement( Severity.ErrorSevere, "Expected to find one type argument in arrayOf call", c )
970973
}

java/ql/consistency-queries/children.ql

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ predicate gapInChildren(Element e, int i) {
2929
and not e instanceof TryStmt
3030
// TODO: Tighten this up:
3131
and not e instanceof ForStmt
32-
// TODO: Tighten this up:
33-
and not e instanceof MethodAccess // extension receiver is now a gap for Java
3432
// Kotlin bug?
3533
and not (e instanceof MethodAccess and e.getFile().getExtension() = "kt")
3634
}

java/ql/lib/semmle/code/java/Expr.qll

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1741,22 +1741,19 @@ class MethodAccess extends Expr, Call, @methodaccess {
17411741
/** Holds if this method access has a qualifier. */
17421742
predicate hasQualifier() { exists(this.getQualifier()) }
17431743

1744-
/** Gets the extension receiver expression of this method access, if any. */
1745-
Expr getExtensionReceiver() { result.isNthChildOf(this, -2) }
1746-
17471744
/** Gets an argument supplied to the method that is invoked using this method access. */
17481745
override Expr getAnArgument() { result.getIndex() >= 0 and result.getParent() = this }
17491746

17501747
/** Gets the argument at the specified (zero-based) position in this method access. */
17511748
override Expr getArgument(int index) { exprs(result, _, _, _, this, index) and index >= 0 }
17521749

17531750
/** Gets a type argument supplied as part of this method access, if any. */
1754-
Expr getATypeArgument() { result.getIndex() <= -3 and result.getParent() = this }
1751+
Expr getATypeArgument() { result.getIndex() <= -2 and result.getParent() = this }
17551752

17561753
/** Gets the type argument at the specified (zero-based) position in this method access, if any. */
17571754
Expr getTypeArgument(int index) {
17581755
result = this.getATypeArgument() and
1759-
(-3 - result.getIndex()) = index
1756+
(-2 - result.getIndex()) = index
17601757
}
17611758

17621759
/** Gets the method accessed by this method access. */

java/ql/test/kotlin/library-tests/variables/variableAccesses.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ varAcc
66
| variables.kt:16:11:16:18 | o |
77
| variables.kt:16:11:16:18 | o |
88
instAcc
9-
| variables.kt:21:9:21:9 | this |
109
| variables.kt:21:11:21:15 | this |
1110
| variables.kt:24:9:24:9 | this |
1211
| variables.kt:25:9:25:9 | this |

0 commit comments

Comments
 (0)