[NI] Fix substitution of NotNullTypeParameter

This commit is contained in:
Mikhail Zarechenskiy
2018-01-19 14:53:49 +03:00
parent 4cd07f59a0
commit 2a0bb68e1c
7 changed files with 57 additions and 30 deletions
@@ -1,17 +1,6 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.resolve.calls.inference.components
@@ -122,6 +111,9 @@ interface NewTypeSubstitutor {
if (type.isDefinitelyNotNullType) {
replacement = replacement.makeDefinitelyNotNullOrNotNull()
}
if (type is CustomTypeVariable) {
replacement = type.substitutionResult(replacement).unwrap()
}
return replacement
}
@@ -0,0 +1,20 @@
// FILE: JClass.java
import org.jetbrains.annotations.NotNull;
public class JClass {
@NotNull
public static <T> T getNotNullT() {
return null;
}
}
// FILE: test.kt
fun <T : Any> test() {
var value: T? = null
if (value == null) {
value = JClass.getNotNullT()
}
<!DEBUG_INFO_SMARTCAST!>value<!>.hashCode() // unsafe call error
}
@@ -0,0 +1,13 @@
package
public fun </*0*/ T : kotlin.Any> test(): kotlin.Unit
public open class JClass {
public constructor JClass()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
// Static members
@org.jetbrains.annotations.NotNull public open fun </*0*/ T : kotlin.Any!> getNotNullT(): T
}
@@ -11,9 +11,9 @@ public class A {
// FILE: k.kt
fun test() {
A.<!OI;TYPE_INFERENCE_INCORPORATION_ERROR!>bar<!>(<!OI;NULL_FOR_NONNULL_TYPE!>null<!>, "")
A.<!OI;TYPE_INFERENCE_INCORPORATION_ERROR!>bar<!>(<!NI;NULL_FOR_NONNULL_TYPE, OI;NULL_FOR_NONNULL_TYPE!>null<!>, "")
A.bar<String>(<!NULL_FOR_NONNULL_TYPE!>null<!>, "")
A.bar<String?>(<!OI;NULL_FOR_NONNULL_TYPE!>null<!>, "")
A.<!OI;TYPE_INFERENCE_INCORPORATION_ERROR!>bar<!>(<!OI;NULL_FOR_NONNULL_TYPE!>null<!>, A.platformString())
A.bar<String?>(<!NI;NULL_FOR_NONNULL_TYPE, OI;NULL_FOR_NONNULL_TYPE!>null<!>, "")
A.<!OI;TYPE_INFERENCE_INCORPORATION_ERROR!>bar<!>(<!NI;NULL_FOR_NONNULL_TYPE, OI;NULL_FOR_NONNULL_TYPE!>null<!>, A.platformString())
}
@@ -14822,6 +14822,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("notnullTypesFromJavaWithSmartcast.kt")
public void testNotnullTypesFromJavaWithSmartcast() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/notnullTypesFromJavaWithSmartcast.kt");
doTest(fileName);
}
@TestMetadata("NullableNothingIsExactlyNull.kt")
public void testNullableNothingIsExactlyNull() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/NullableNothingIsExactlyNull.kt");
@@ -14822,6 +14822,12 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
doTest(fileName);
}
@TestMetadata("notnullTypesFromJavaWithSmartcast.kt")
public void testNotnullTypesFromJavaWithSmartcast() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/notnullTypesFromJavaWithSmartcast.kt");
doTest(fileName);
}
@TestMetadata("NullableNothingIsExactlyNull.kt")
public void testNullableNothingIsExactlyNull() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/NullableNothingIsExactlyNull.kt");
@@ -1,17 +1,6 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.types;
@@ -29,6 +18,7 @@ import org.jetbrains.kotlin.descriptors.annotations.Annotations;
import org.jetbrains.kotlin.resolve.constants.IntegerValueTypeConstructor;
import org.jetbrains.kotlin.resolve.scopes.MemberScope;
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker;
import org.jetbrains.kotlin.types.checker.NewTypeVariableConstructor;
import java.util.*;
@@ -467,7 +457,7 @@ public class TypeUtils {
}
public static boolean isTypeParameter(@NotNull KotlinType type) {
return getTypeParameterDescriptorOrNull(type) != null;
return getTypeParameterDescriptorOrNull(type) != null || type.getConstructor() instanceof NewTypeVariableConstructor;
}
public static boolean isReifiedTypeParameter(@NotNull KotlinType type) {