mirror of
https://github.com/github/codeql.git
synced 2025-12-20 18:56:32 +01:00
Extract not-null expression
This commit is contained in:
@@ -534,6 +534,9 @@
|
||||
| exprs.kt:193:31:193:37 | ... + ... | exprs.kt:192:16:194:9 | <obinit> | AddExpr |
|
||||
| exprs.kt:193:36:193:37 | a2 | exprs.kt:192:16:194:9 | <obinit> | VarAccess |
|
||||
| exprs.kt:193:40:193:49 | toString(...) | exprs.kt:192:16:194:9 | <obinit> | MethodAccess |
|
||||
| exprs.kt:199:5:199:20 | y | exprs.kt:198:1:200:1 | notNullAssertion | LocalVariableDeclExpr |
|
||||
| exprs.kt:199:18:199:18 | x | exprs.kt:198:1:200:1 | notNullAssertion | VarAccess |
|
||||
| exprs.kt:199:19:199:20 | ...!! | exprs.kt:198:1:200:1 | notNullAssertion | NotNullExpr |
|
||||
| file://:0:0:0:0 | C | exprs.kt:146:5:146:33 | foo | TypeAccess |
|
||||
| file://:0:0:0:0 | Color | exprs.kt:175:6:179:1 | Color | TypeAccess |
|
||||
| file://:0:0:0:0 | Direction | exprs.kt:171:6:173:1 | Direction | TypeAccess |
|
||||
|
||||
@@ -194,3 +194,7 @@ class Class1 {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun notNullAssertion(x: Any?) {
|
||||
val y: Any = x!!
|
||||
}
|
||||
|
||||
1
java/ql/test/kotlin/library-tests/exprs/unaryOp.expected
Normal file
1
java/ql/test/kotlin/library-tests/exprs/unaryOp.expected
Normal file
@@ -0,0 +1 @@
|
||||
| exprs.kt:199:19:199:20 | ...!! | exprs.kt:199:18:199:18 | x |
|
||||
36
java/ql/test/kotlin/library-tests/exprs/unaryOp.ql
Normal file
36
java/ql/test/kotlin/library-tests/exprs/unaryOp.ql
Normal file
@@ -0,0 +1,36 @@
|
||||
import java
|
||||
|
||||
newtype TMaybeElement =
|
||||
TElement(Element e) or
|
||||
TNoElement()
|
||||
|
||||
class MaybeElement extends TMaybeElement {
|
||||
abstract string toString();
|
||||
|
||||
abstract Location getLocation();
|
||||
}
|
||||
|
||||
class YesMaybeElement extends MaybeElement {
|
||||
Element e;
|
||||
|
||||
YesMaybeElement() { this = TElement(e) }
|
||||
|
||||
override string toString() { result = e.toString() }
|
||||
|
||||
override Location getLocation() { result = e.getLocation() }
|
||||
}
|
||||
|
||||
class NoMaybeElement extends MaybeElement {
|
||||
NoMaybeElement() { this = TNoElement() }
|
||||
|
||||
override string toString() { result = "<none>" }
|
||||
|
||||
override Location getLocation() { none() }
|
||||
}
|
||||
|
||||
MaybeElement op(UnaryExpr e) {
|
||||
if exists(e.getExpr()) then result = TElement(e.getExpr()) else result = TNoElement()
|
||||
}
|
||||
|
||||
from Expr e
|
||||
select e, op(e)
|
||||
Reference in New Issue
Block a user