Do not approximate DefinitelyNotNullType in public declarations
Because since 1.6 they become normal denotable types ^KT-26245 Fixed
This commit is contained in:
committed by
TeamCityServer
parent
e74a0c7ef7
commit
37f923a98f
+12
@@ -9179,12 +9179,24 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
|||||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/explicitDefinitelyNotNull"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
|
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/explicitDefinitelyNotNull"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("approximation.kt")
|
||||||
|
public void testApproximation() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/explicitDefinitelyNotNull/approximation.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("disabledFeature.kt")
|
@TestMetadata("disabledFeature.kt")
|
||||||
public void testDisabledFeature() throws Exception {
|
public void testDisabledFeature() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/tests/explicitDefinitelyNotNull/disabledFeature.kt");
|
runTest("compiler/testData/diagnostics/tests/explicitDefinitelyNotNull/disabledFeature.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("inference.kt")
|
||||||
|
public void testInference() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/explicitDefinitelyNotNull/inference.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("notApplicable.kt")
|
@TestMetadata("notApplicable.kt")
|
||||||
public void testNotApplicable() throws Exception {
|
public void testNotApplicable() throws Exception {
|
||||||
|
|||||||
+1
-1
@@ -365,7 +365,7 @@ abstract class AbstractTypeApproximator(
|
|||||||
return typeWithErasedNullability
|
return typeWithErasedNullability
|
||||||
}
|
}
|
||||||
|
|
||||||
return if (conf.definitelyNotNullType) {
|
return if (conf.definitelyNotNullType || languageVersionSettings.supportsFeature(LanguageFeature.DefinitelyNotNullTypeParameters)) {
|
||||||
approximatedOriginalType?.makeDefinitelyNotNullOrNotNull()
|
approximatedOriginalType?.makeDefinitelyNotNullOrNotNull()
|
||||||
} else {
|
} else {
|
||||||
if (toSuper)
|
if (toSuper)
|
||||||
|
|||||||
+14
@@ -0,0 +1,14 @@
|
|||||||
|
// !LANGUAGE: +DefinitelyNotNullTypeParameters
|
||||||
|
|
||||||
|
fun <T> foo(x: T, y: T!!) = x!!
|
||||||
|
|
||||||
|
fun main() {
|
||||||
|
foo<String>("", "").length
|
||||||
|
<!INAPPLICABLE_CANDIDATE!>foo<!><String>("", null).length
|
||||||
|
foo<String?>(null, "").length
|
||||||
|
foo<String?>(null, null).length
|
||||||
|
|
||||||
|
foo("", "").length
|
||||||
|
foo("", null).length
|
||||||
|
foo(null, "").length
|
||||||
|
}
|
||||||
+14
@@ -0,0 +1,14 @@
|
|||||||
|
// !LANGUAGE: +DefinitelyNotNullTypeParameters
|
||||||
|
|
||||||
|
fun <T> foo(x: T, y: T!!) = x!!
|
||||||
|
|
||||||
|
fun main() {
|
||||||
|
foo<String>("", "").length
|
||||||
|
foo<String>("", <!NULL_FOR_NONNULL_TYPE!>null<!>).length
|
||||||
|
foo<String?>(null, "").length
|
||||||
|
foo<String?>(null, <!NULL_FOR_NONNULL_TYPE!>null<!>).length
|
||||||
|
|
||||||
|
foo("", "").length
|
||||||
|
foo("", <!NULL_FOR_NONNULL_TYPE!>null<!>).length
|
||||||
|
foo(null, "").length
|
||||||
|
}
|
||||||
+4
@@ -0,0 +1,4 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
public fun </*0*/ T> foo(/*0*/ x: T, /*1*/ y: T!!): T!!
|
||||||
|
public fun main(): kotlin.Unit
|
||||||
+33
@@ -0,0 +1,33 @@
|
|||||||
|
// !LANGUAGE: +DefinitelyNotNullTypeParameters
|
||||||
|
|
||||||
|
fun <T> toDefNotNull(s: T): T!! = s!!
|
||||||
|
|
||||||
|
fun <K> removeQuestionMark(x: K?): K = x!!
|
||||||
|
|
||||||
|
fun Any.foo() {}
|
||||||
|
|
||||||
|
fun <E> expectNN(e: E!!) {}
|
||||||
|
|
||||||
|
fun <F> main(x: F, y: F, z: F, w: F, m: F) {
|
||||||
|
val y1 = toDefNotNull(x) // K instead of K!!
|
||||||
|
val y2: F!! = toDefNotNull(x) // K instead of K!!
|
||||||
|
val x1 = removeQuestionMark(x) // T or T!!
|
||||||
|
val x2: F!! = removeQuestionMark(x) // T or T!!
|
||||||
|
|
||||||
|
val z1 = x!!
|
||||||
|
val z2: F!! = y!!
|
||||||
|
val w1 = if (z != null) z else return
|
||||||
|
val w2: F!! = if (w != null) w else return
|
||||||
|
|
||||||
|
y1.<!INAPPLICABLE_CANDIDATE!>foo<!>()
|
||||||
|
y2.<!INAPPLICABLE_CANDIDATE!>foo<!>()
|
||||||
|
x1.foo()
|
||||||
|
x2.<!INAPPLICABLE_CANDIDATE!>foo<!>()
|
||||||
|
z1.foo()
|
||||||
|
z2.<!INAPPLICABLE_CANDIDATE!>foo<!>()
|
||||||
|
w1.foo()
|
||||||
|
w2.<!INAPPLICABLE_CANDIDATE!>foo<!>()
|
||||||
|
|
||||||
|
expectNN(m)
|
||||||
|
expectNN(m!!)
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
// !LANGUAGE: +DefinitelyNotNullTypeParameters
|
||||||
|
|
||||||
|
fun <T> toDefNotNull(s: T): T!! = s!!
|
||||||
|
|
||||||
|
fun <K> removeQuestionMark(x: K?): K = x!!
|
||||||
|
|
||||||
|
fun Any.foo() {}
|
||||||
|
|
||||||
|
fun <E> expectNN(e: E!!) {}
|
||||||
|
|
||||||
|
fun <F> main(x: F, y: F, z: F, w: F, m: F) {
|
||||||
|
val y1 = toDefNotNull(x) // K instead of K!!
|
||||||
|
val y2: F!! = toDefNotNull(x) // K instead of K!!
|
||||||
|
val x1 = removeQuestionMark(x) // T or T!!
|
||||||
|
val x2: F!! = removeQuestionMark(x) // T or T!!
|
||||||
|
|
||||||
|
val z1 = x!!
|
||||||
|
val z2: F!! = y!!
|
||||||
|
val w1 = if (z != null) <!DEBUG_INFO_SMARTCAST!>z<!> else return
|
||||||
|
val w2: F!! = if (w != null) <!DEBUG_INFO_SMARTCAST!>w<!> else return
|
||||||
|
|
||||||
|
y1.foo()
|
||||||
|
y2.foo()
|
||||||
|
x1.foo()
|
||||||
|
x2.foo()
|
||||||
|
z1.foo()
|
||||||
|
z2.foo()
|
||||||
|
w1.foo()
|
||||||
|
w2.foo()
|
||||||
|
|
||||||
|
expectNN(<!TYPE_MISMATCH!>m<!>)
|
||||||
|
expectNN(m!!)
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
public fun </*0*/ E> expectNN(/*0*/ e: E!!): kotlin.Unit
|
||||||
|
public fun </*0*/ F> main(/*0*/ x: F, /*1*/ y: F, /*2*/ z: F, /*3*/ w: F, /*4*/ m: F): kotlin.Unit
|
||||||
|
public fun </*0*/ K> removeQuestionMark(/*0*/ x: K?): K
|
||||||
|
public fun </*0*/ T> toDefNotNull(/*0*/ s: T): T!!
|
||||||
|
public fun kotlin.Any.foo(): kotlin.Unit
|
||||||
Generated
+12
@@ -9185,12 +9185,24 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
|||||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/explicitDefinitelyNotNull"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
|
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/explicitDefinitelyNotNull"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("approximation.kt")
|
||||||
|
public void testApproximation() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/explicitDefinitelyNotNull/approximation.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("disabledFeature.kt")
|
@TestMetadata("disabledFeature.kt")
|
||||||
public void testDisabledFeature() throws Exception {
|
public void testDisabledFeature() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/tests/explicitDefinitelyNotNull/disabledFeature.kt");
|
runTest("compiler/testData/diagnostics/tests/explicitDefinitelyNotNull/disabledFeature.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("inference.kt")
|
||||||
|
public void testInference() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/explicitDefinitelyNotNull/inference.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("notApplicable.kt")
|
@TestMetadata("notApplicable.kt")
|
||||||
public void testNotApplicable() throws Exception {
|
public void testNotApplicable() throws Exception {
|
||||||
|
|||||||
Reference in New Issue
Block a user