Add QL for ::class expression, and add test

This commit is contained in:
Tamas Vajk
2021-09-21 11:25:22 +02:00
committed by Ian Lynagh
parent e8a079b56a
commit 9889f49560
3 changed files with 17 additions and 3 deletions

View File

@@ -2143,9 +2143,7 @@ class WhenExpr extends Expr, @whenexpr {
override string getAPrimaryQlClass() { result = "WhenExpr" }
/** Gets the `i`th branch. */
WhenBranch getBranch(int i) {
when_branch(result, this, i)
}
WhenBranch getBranch(int i) { when_branch(result, this, i) }
}
/** A Kotlin `when` branch. */
@@ -2163,3 +2161,13 @@ class WhenBranch extends Top, @whenbranch {
override string getAPrimaryQlClass() { result = "WhenBranch" }
}
/** A Kotlin `::class` expression. */
class ClassExpr extends Expr, @getclassexpr {
/** Gets the expression whose class is being returned. */
Expr getExpr() { result.isNthChildOf(this, 0) }
override string toString() { result = "::class" }
override string getAPrimaryQlClass() { result = "ClassExpr" }
}

View File

@@ -41,12 +41,15 @@
| exprs.kt:46:12:46:14 | 123 | IntegerLiteral |
| exprs.kt:46:12:46:20 | ... + ... | AddExpr |
| exprs.kt:46:18:46:20 | 456 | IntegerLiteral |
| exprs.kt:50:13:50:16 | true | BooleanLiteral |
| exprs.kt:50:13:50:23 | ::class | ClassExpr |
| file://:0:0:0:0 | b1 | LocalVariableDeclExpr |
| file://:0:0:0:0 | b2 | LocalVariableDeclExpr |
| file://:0:0:0:0 | b6 | LocalVariableDeclExpr |
| file://:0:0:0:0 | b7 | LocalVariableDeclExpr |
| file://:0:0:0:0 | b8 | LocalVariableDeclExpr |
| file://:0:0:0:0 | c | LocalVariableDeclExpr |
| file://:0:0:0:0 | d | LocalVariableDeclExpr |
| file://:0:0:0:0 | i1 | LocalVariableDeclExpr |
| file://:0:0:0:0 | i2 | LocalVariableDeclExpr |
| file://:0:0:0:0 | i3 | LocalVariableDeclExpr |

View File

@@ -46,3 +46,6 @@ TODO
return 123 + 456
}
fun getClass() {
val d = true::class
}