FIR: Use flexible type for generic parameters bounds

Otherwise star projections may be incorrectly approximated to strictly
nullable types (as in test)
This commit is contained in:
Denis Zharkov
2020-02-11 14:08:35 +03:00
parent 5a2cdfcab4
commit bc34bc3f96
5 changed files with 30 additions and 1 deletions
@@ -92,7 +92,7 @@ class JavaSymbolProvider(
stack: JavaTypeParameterStack,
) {
for (upperBound in javaTypeParameter.upperBounds) {
bounds += upperBound.toFirResolvedTypeRef(this@JavaSymbolProvider.session, stack, nullability = ConeNullability.NULLABLE)
bounds += upperBound.toFirResolvedTypeRef(this@JavaSymbolProvider.session, stack, nullability = ConeNullability.UNKNOWN)
}
addDefaultBoundIfNecessary()
}
@@ -0,0 +1,11 @@
// FILE: B.java
public class B<E extends A> {}
// FILE: main.kt
interface A {}
fun <D : A> foo(b: B<D>) {}
fun main(b: B<*>) {
foo(b)
}
@@ -0,0 +1,8 @@
FILE: main.kt
public abstract interface A : R|kotlin/Any| {
}
public final fun <D : R|A|> foo(b: R|B<D>|): R|kotlin/Unit| {
}
public final fun main(b: R|B<*>|): R|kotlin/Unit| {
R|/foo|<R|captured type: lowerType = null|>(R|<local>/b|)
}
@@ -924,6 +924,11 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest {
runTest("compiler/fir/resolve/testData/resolve/inference/callableReferenceOnInstance.kt");
}
@TestMetadata("capturedTypeForJavaTypeParameter.kt")
public void testCapturedTypeForJavaTypeParameter() throws Exception {
runTest("compiler/fir/resolve/testData/resolve/inference/capturedTypeForJavaTypeParameter.kt");
}
@TestMetadata("nestedLambdas.kt")
public void testNestedLambdas() throws Exception {
runTest("compiler/fir/resolve/testData/resolve/inference/nestedLambdas.kt");
@@ -924,6 +924,11 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
runTest("compiler/fir/resolve/testData/resolve/inference/callableReferenceOnInstance.kt");
}
@TestMetadata("capturedTypeForJavaTypeParameter.kt")
public void testCapturedTypeForJavaTypeParameter() throws Exception {
runTest("compiler/fir/resolve/testData/resolve/inference/capturedTypeForJavaTypeParameter.kt");
}
@TestMetadata("nestedLambdas.kt")
public void testNestedLambdas() throws Exception {
runTest("compiler/fir/resolve/testData/resolve/inference/nestedLambdas.kt");