Merge pull request #11003 from smowton/smowton/fix/reintroduce-pointless-wildcards

Kotlin: reintroduce pointless wildcards when a Java declaration explicitly uses them
This commit is contained in:
Chris Smowton
2022-10-27 16:06:21 +01:00
committed by GitHub
7 changed files with 38 additions and 3 deletions

View File

@@ -0,0 +1,9 @@
public class Test {
// This gets mapped to kotlin.Iterable<out T>, meaning we must reintroduce the use-site extends variance to get a type consistent with Java.
public static void needlessExtends(Iterable<? extends String> l) { }
// This type is defined KotlinConsumer<in T>, meaning we must reintroduce the use-site extends variance to get a type consistent with Java.
public static void needlessSuper(KotlinConsumer<? super Object> l) { }
}

View File

@@ -0,0 +1 @@
public class KotlinConsumer<in T> { }

View File

@@ -0,0 +1,2 @@
| Test.java:4:22:4:36 | needlessExtends | file:///modules/java.base/java/lang/Iterable.class:0:0:0:0 | Iterable<? extends String> |
| Test.java:7:22:7:34 | needlessSuper | build1/KotlinConsumer.class:0:0:0:0 | KotlinConsumer<? super Object> |

View File

@@ -0,0 +1,5 @@
from create_database_utils import *
os.mkdir('build1')
os.mkdir('build2')
run_codeql_database_create(["kotlinc kConsumer.kt -d build1", "javac Test.java -cp build1 -d build2", "kotlinc user.kt -cp build1:build2"], lang="java")

View File

@@ -0,0 +1,5 @@
import java
from Method m
where m.fromSource()
select m, m.getAParamType()

View File

@@ -0,0 +1,4 @@
fun f() {
Test.needlessExtends(null)
Test.needlessSuper(null)
}