Skip to content

Commit 43f2380

Browse files
committed
Kotlin: Add test for extension $default functions
1 parent 387a673 commit 43f2380

File tree

5 files changed

+74
-16
lines changed

5 files changed

+74
-16
lines changed

java/ql/test/kotlin/library-tests/methods/exprs.expected

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -293,12 +293,47 @@
293293
| methods2.kt:8:5:9:5 | Unit | TypeAccess |
294294
| methods2.kt:8:27:8:32 | int | TypeAccess |
295295
| methods2.kt:8:35:8:40 | int | TypeAccess |
296-
| methods3.kt:3:1:3:42 | Unit | TypeAccess |
297-
| methods3.kt:3:5:3:7 | int | TypeAccess |
298-
| methods3.kt:3:33:3:38 | int | TypeAccess |
299-
| methods3.kt:6:5:6:46 | Unit | TypeAccess |
300-
| methods3.kt:6:9:6:11 | int | TypeAccess |
301-
| methods3.kt:6:37:6:42 | int | TypeAccess |
296+
| methods3.kt:3:1:3:49 | 0 | IntegerLiteral |
297+
| methods3.kt:3:1:3:49 | 1 | IntegerLiteral |
298+
| methods3.kt:3:1:3:49 | ... & ... | AndBitwiseExpr |
299+
| methods3.kt:3:1:3:49 | ... == ... | EQExpr |
300+
| methods3.kt:3:1:3:49 | ...=... | AssignExpr |
301+
| methods3.kt:3:1:3:49 | Methods3Kt | TypeAccess |
302+
| methods3.kt:3:1:3:49 | Object | TypeAccess |
303+
| methods3.kt:3:1:3:49 | String | TypeAccess |
304+
| methods3.kt:3:1:3:49 | Unit | TypeAccess |
305+
| methods3.kt:3:1:3:49 | Unit | TypeAccess |
306+
| methods3.kt:3:1:3:49 | fooBarTopLevelMethodExt(...) | MethodAccess |
307+
| methods3.kt:3:1:3:49 | int | TypeAccess |
308+
| methods3.kt:3:1:3:49 | int | TypeAccess |
309+
| methods3.kt:3:1:3:49 | p0 | VarAccess |
310+
| methods3.kt:3:1:3:49 | p1 | VarAccess |
311+
| methods3.kt:3:1:3:49 | p1 | VarAccess |
312+
| methods3.kt:3:1:3:49 | p2 | VarAccess |
313+
| methods3.kt:3:5:3:10 | String | TypeAccess |
314+
| methods3.kt:3:36:3:45 | int | TypeAccess |
315+
| methods3.kt:3:45:3:45 | 1 | IntegerLiteral |
316+
| methods3.kt:6:5:6:45 | 0 | IntegerLiteral |
317+
| methods3.kt:6:5:6:45 | 1 | IntegerLiteral |
318+
| methods3.kt:6:5:6:45 | ... & ... | AndBitwiseExpr |
319+
| methods3.kt:6:5:6:45 | ... == ... | EQExpr |
320+
| methods3.kt:6:5:6:45 | ...=... | AssignExpr |
321+
| methods3.kt:6:5:6:45 | Class3 | TypeAccess |
322+
| methods3.kt:6:5:6:45 | Object | TypeAccess |
323+
| methods3.kt:6:5:6:45 | String | TypeAccess |
324+
| methods3.kt:6:5:6:45 | Unit | TypeAccess |
325+
| methods3.kt:6:5:6:45 | Unit | TypeAccess |
326+
| methods3.kt:6:5:6:45 | fooBarMethodExt(...) | MethodAccess |
327+
| methods3.kt:6:5:6:45 | int | TypeAccess |
328+
| methods3.kt:6:5:6:45 | int | TypeAccess |
329+
| methods3.kt:6:5:6:45 | p0 | VarAccess |
330+
| methods3.kt:6:5:6:45 | p1 | VarAccess |
331+
| methods3.kt:6:5:6:45 | p2 | VarAccess |
332+
| methods3.kt:6:5:6:45 | p2 | VarAccess |
333+
| methods3.kt:6:5:6:45 | p3 | VarAccess |
334+
| methods3.kt:6:9:6:14 | String | TypeAccess |
335+
| methods3.kt:6:32:6:41 | int | TypeAccess |
336+
| methods3.kt:6:41:6:41 | 1 | IntegerLiteral |
302337
| methods4.kt:7:5:7:34 | Unit | TypeAccess |
303338
| methods4.kt:7:11:7:29 | InsideNestedTest | TypeAccess |
304339
| methods5.kt:3:1:11:1 | Unit | TypeAccess |

java/ql/test/kotlin/library-tests/methods/methods.expected

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ methods
3838
| enumClass.kt:8:3:11:4 | VAL | enumClass.kt:10:14:10:42 | g | g(int) | override, public | |
3939
| methods2.kt:0:0:0:0 | Methods2Kt | methods2.kt:4:1:5:1 | fooBarTopLevelMethod | fooBarTopLevelMethod(int,int) | final, public, static | |
4040
| methods2.kt:7:1:10:1 | Class2 | methods2.kt:8:5:9:5 | fooBarClassMethod | fooBarClassMethod(int,int) | final, public | |
41-
| methods3.kt:0:0:0:0 | Methods3Kt | methods3.kt:3:1:3:42 | fooBarTopLevelMethodExt | fooBarTopLevelMethodExt(int,int) | final, public, static | |
42-
| methods3.kt:5:1:7:1 | Class3 | methods3.kt:6:5:6:46 | fooBarTopLevelMethodExt | fooBarTopLevelMethodExt(int,int) | final, public | |
41+
| methods3.kt:0:0:0:0 | Methods3Kt | methods3.kt:3:1:3:49 | fooBarTopLevelMethodExt | fooBarTopLevelMethodExt(java.lang.String,int) | final, public, static | |
42+
| methods3.kt:0:0:0:0 | Methods3Kt | methods3.kt:3:1:3:49 | fooBarTopLevelMethodExt$default | fooBarTopLevelMethodExt$default(java.lang.String,int,int,java.lang.Object) | public, static | Compiler generated |
43+
| methods3.kt:5:1:7:1 | Class3 | methods3.kt:6:5:6:45 | fooBarMethodExt | fooBarMethodExt(java.lang.String,int) | final, public | |
44+
| methods3.kt:5:1:7:1 | Class3 | methods3.kt:6:5:6:45 | fooBarMethodExt$default | fooBarMethodExt$default(java.lang.String,foo.bar.Class3,int,int,java.lang.Object) | public, static | Compiler generated |
4345
| methods4.kt:5:3:9:3 | InsideNestedTest | methods4.kt:7:5:7:34 | m | m(foo.bar.NestedTest.InsideNestedTest) | final, public | |
4446
| methods5.kt:0:0:0:0 | Methods5Kt | methods5.kt:3:1:11:1 | x | x() | final, public, static | |
4547
| methods5.kt:5:3:5:27 | | methods5.kt:5:3:5:27 | a | a(int) | final, public | |
@@ -74,6 +76,9 @@ constructors
7476
| methods5.kt:13:1:13:14 | C1 | methods5.kt:13:1:13:14 | C1 | C1() |
7577
| methods.kt:5:1:20:1 | Class | methods.kt:5:1:20:1 | Class | Class() |
7678
extensions
77-
| methods3.kt:3:1:3:42 | fooBarTopLevelMethodExt | file://:0:0:0:0 | int |
78-
| methods3.kt:6:5:6:46 | fooBarTopLevelMethodExt | file://:0:0:0:0 | int |
79+
| methods3.kt:3:1:3:49 | fooBarTopLevelMethodExt | file:///modules/java.base/java/lang/String.class:0:0:0:0 | String |
80+
| methods3.kt:6:5:6:45 | fooBarMethodExt | file:///modules/java.base/java/lang/String.class:0:0:0:0 | String |
7981
| methods5.kt:9:3:9:32 | f1 | file:///!unknown-binary-location/foo/bar/C1.class:0:0:0:0 | C1<T1> |
82+
extensionsMismatch
83+
| methods3.kt:3:1:3:49 | fooBarTopLevelMethodExt | methods3.kt:3:1:3:49 | fooBarTopLevelMethodExt$default |
84+
| methods3.kt:6:5:6:45 | fooBarMethodExt | methods3.kt:6:5:6:45 | fooBarMethodExt$default |

java/ql/test/kotlin/library-tests/methods/methods.ql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,12 @@ query predicate constructors(RefType declType, Constructor c, string signature)
1717
}
1818

1919
query predicate extensions(ExtensionMethod m, Type t) { m.getExtendedType() = t and m.fromSource() }
20+
21+
query predicate extensionsMismatch(Method src, Method def) {
22+
src.getKotlinParameterDefaultsProxy() = def and
23+
(
24+
src instanceof ExtensionMethod and not def instanceof ExtensionMethod
25+
or
26+
def instanceof ExtensionMethod and not src instanceof ExtensionMethod
27+
)
28+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package foo.bar
22

3-
fun Int.fooBarTopLevelMethodExt(x: Int) {}
3+
fun String.fooBarTopLevelMethodExt(x: Int = 1) {}
44

55
class Class3 {
6-
fun Int.fooBarTopLevelMethodExt(x: Int) {}
6+
fun String.fooBarMethodExt(x: Int = 1) {}
77
}

java/ql/test/kotlin/library-tests/methods/parameters.expected

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,19 @@
3232
| methods2.kt:4:1:5:1 | fooBarTopLevelMethod | methods2.kt:4:34:4:39 | y | 1 |
3333
| methods2.kt:8:5:9:5 | fooBarClassMethod | methods2.kt:8:27:8:32 | x | 0 |
3434
| methods2.kt:8:5:9:5 | fooBarClassMethod | methods2.kt:8:35:8:40 | y | 1 |
35-
| methods3.kt:3:1:3:42 | fooBarTopLevelMethodExt | methods3.kt:3:5:3:7 | <this> | 0 |
36-
| methods3.kt:3:1:3:42 | fooBarTopLevelMethodExt | methods3.kt:3:33:3:38 | x | 1 |
37-
| methods3.kt:6:5:6:46 | fooBarTopLevelMethodExt | methods3.kt:6:9:6:11 | <this> | 0 |
38-
| methods3.kt:6:5:6:46 | fooBarTopLevelMethodExt | methods3.kt:6:37:6:42 | x | 1 |
35+
| methods3.kt:3:1:3:49 | fooBarTopLevelMethodExt | methods3.kt:3:5:3:10 | <this> | 0 |
36+
| methods3.kt:3:1:3:49 | fooBarTopLevelMethodExt | methods3.kt:3:36:3:45 | x | 1 |
37+
| methods3.kt:3:1:3:49 | fooBarTopLevelMethodExt$default | methods3.kt:3:1:3:49 | p0 | 0 |
38+
| methods3.kt:3:1:3:49 | fooBarTopLevelMethodExt$default | methods3.kt:3:1:3:49 | p1 | 1 |
39+
| methods3.kt:3:1:3:49 | fooBarTopLevelMethodExt$default | methods3.kt:3:1:3:49 | p2 | 2 |
40+
| methods3.kt:3:1:3:49 | fooBarTopLevelMethodExt$default | methods3.kt:3:1:3:49 | p3 | 3 |
41+
| methods3.kt:6:5:6:45 | fooBarMethodExt | methods3.kt:6:9:6:14 | <this> | 0 |
42+
| methods3.kt:6:5:6:45 | fooBarMethodExt | methods3.kt:6:32:6:41 | x | 1 |
43+
| methods3.kt:6:5:6:45 | fooBarMethodExt$default | methods3.kt:6:5:6:45 | p0 | 0 |
44+
| methods3.kt:6:5:6:45 | fooBarMethodExt$default | methods3.kt:6:5:6:45 | p1 | 1 |
45+
| methods3.kt:6:5:6:45 | fooBarMethodExt$default | methods3.kt:6:5:6:45 | p2 | 2 |
46+
| methods3.kt:6:5:6:45 | fooBarMethodExt$default | methods3.kt:6:5:6:45 | p3 | 3 |
47+
| methods3.kt:6:5:6:45 | fooBarMethodExt$default | methods3.kt:6:5:6:45 | p4 | 4 |
3948
| methods4.kt:7:5:7:34 | m | methods4.kt:7:11:7:29 | x | 0 |
4049
| methods5.kt:5:3:5:27 | a | methods5.kt:5:13:5:18 | i | 0 |
4150
| methods5.kt:9:3:9:32 | f1 | methods5.kt:9:12:9:17 | <this> | 0 |

0 commit comments

Comments
 (0)