diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java index 6189cad6dbc..035cf35c2d4 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java @@ -10116,6 +10116,76 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti } } + @Nested + @TestMetadata("compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection") + @TestDataPath("$PROJECT_ROOT") + public class ExplicitDefinitelyNotNullableViaIntersection { + @Test + public void testAllFilesPresentInExplicitDefinitelyNotNullableViaIntersection() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @Test + @TestMetadata("approximation.kt") + public void testApproximation() throws Exception { + runTest("compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/approximation.kt"); + } + + @Test + @TestMetadata("bareTypes.kt") + public void testBareTypes() throws Exception { + runTest("compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/bareTypes.kt"); + } + + @Test + @TestMetadata("disabledFeature.kt") + public void testDisabledFeature() throws Exception { + runTest("compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/disabledFeature.kt"); + } + + @Test + @TestMetadata("inference.kt") + public void testInference() throws Exception { + runTest("compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/inference.kt"); + } + + @Test + @TestMetadata("isAsOperators.kt") + public void testIsAsOperators() throws Exception { + runTest("compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/isAsOperators.kt"); + } + + @Test + @TestMetadata("isAsOperatorsEnabled.kt") + public void testIsAsOperatorsEnabled() throws Exception { + runTest("compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/isAsOperatorsEnabled.kt"); + } + + @Test + @TestMetadata("notApplicable.kt") + public void testNotApplicable() throws Exception { + runTest("compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/notApplicable.kt"); + } + + @Test + @TestMetadata("overrides.kt") + public void testOverrides() throws Exception { + runTest("compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/overrides.kt"); + } + + @Test + @TestMetadata("overridesJavaAnnotated.kt") + public void testOverridesJavaAnnotated() throws Exception { + runTest("compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/overridesJavaAnnotated.kt"); + } + + @Test + @TestMetadata("simple.kt") + public void testSimple() throws Exception { + runTest("compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/simple.kt"); + } + } + @Nested @TestMetadata("compiler/testData/diagnostics/tests/exposed") @TestDataPath("$PROJECT_ROOT") diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java index e01a74276bb..c3399b7a37d 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java @@ -10116,6 +10116,76 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac } } + @Nested + @TestMetadata("compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection") + @TestDataPath("$PROJECT_ROOT") + public class ExplicitDefinitelyNotNullableViaIntersection { + @Test + public void testAllFilesPresentInExplicitDefinitelyNotNullableViaIntersection() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @Test + @TestMetadata("approximation.kt") + public void testApproximation() throws Exception { + runTest("compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/approximation.kt"); + } + + @Test + @TestMetadata("bareTypes.kt") + public void testBareTypes() throws Exception { + runTest("compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/bareTypes.kt"); + } + + @Test + @TestMetadata("disabledFeature.kt") + public void testDisabledFeature() throws Exception { + runTest("compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/disabledFeature.kt"); + } + + @Test + @TestMetadata("inference.kt") + public void testInference() throws Exception { + runTest("compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/inference.kt"); + } + + @Test + @TestMetadata("isAsOperators.kt") + public void testIsAsOperators() throws Exception { + runTest("compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/isAsOperators.kt"); + } + + @Test + @TestMetadata("isAsOperatorsEnabled.kt") + public void testIsAsOperatorsEnabled() throws Exception { + runTest("compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/isAsOperatorsEnabled.kt"); + } + + @Test + @TestMetadata("notApplicable.kt") + public void testNotApplicable() throws Exception { + runTest("compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/notApplicable.kt"); + } + + @Test + @TestMetadata("overrides.kt") + public void testOverrides() throws Exception { + runTest("compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/overrides.kt"); + } + + @Test + @TestMetadata("overridesJavaAnnotated.kt") + public void testOverridesJavaAnnotated() throws Exception { + runTest("compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/overridesJavaAnnotated.kt"); + } + + @Test + @TestMetadata("simple.kt") + public void testSimple() throws Exception { + runTest("compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/simple.kt"); + } + } + @Nested @TestMetadata("compiler/testData/diagnostics/tests/exposed") @TestDataPath("$PROJECT_ROOT") diff --git a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/DeclarationsConverter.kt b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/DeclarationsConverter.kt index ae85e5d4087..34e02b2cc82 100644 --- a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/DeclarationsConverter.kt +++ b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/DeclarationsConverter.kt @@ -1810,6 +1810,11 @@ class DeclarationsConverter( source = typeRefSource isMarkedNullable = false } + INTERSECTION_TYPE -> firType = + buildErrorTypeRef { + source = typeRefSource + diagnostic = ConeSimpleDiagnostic("Intersection types are not supported yet", DiagnosticKind.Syntax) + } TokenType.ERROR_ELEMENT -> firType = buildErrorTypeRef { source = typeRefSource @@ -1861,12 +1866,15 @@ class DeclarationsConverter( USER_TYPE -> firType = convertUserType(typeRefSource, it, isNullable) FUNCTION_TYPE -> firType = convertFunctionType(typeRefSource, it, isNullable, isSuspend = allTypeModifiers.hasSuspend()) NULLABLE_TYPE -> firType = convertNullableType(typeRefSource, it, allTypeModifiers) - DEFINITELY_NOT_NULL_TYPE -> firType = - unwrapDefinitelyNotNullableType(typeRefSource, it, allTypeModifiers, isNullable = true) DYNAMIC_TYPE -> firType = buildDynamicTypeRef { source = typeRefSource isMarkedNullable = true } + INTERSECTION_TYPE -> firType = + buildErrorTypeRef { + source = typeRefSource + diagnostic = ConeSimpleDiagnostic("Intersection types are not supported yet", DiagnosticKind.Syntax) + } } } diff --git a/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt b/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt index 04a9432cfc2..ec9a0c186f3 100644 --- a/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt +++ b/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt @@ -1605,6 +1605,10 @@ open class RawFirBuilder( } } } + is KtIntersectionType -> FirErrorTypeRefBuilder().apply { + this.source = source + diagnostic = ConeSimpleDiagnostic("Intersection types are not supported yet", DiagnosticKind.Syntax) + } null -> FirErrorTypeRefBuilder().apply { this.source = source diagnostic = ConeSimpleDiagnostic("Unwrapped type is null", DiagnosticKind.Syntax) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index 59ad9856263..d533a949ade 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -161,6 +161,8 @@ public interface Errors { DiagnosticFactory0 REDUNDANT_NULLABLE = DiagnosticFactory0.create(WARNING, NULLABLE_TYPE); DiagnosticFactory0 DEFINITELY_NOT_NULLABLE_NOT_APPLICABLE = DiagnosticFactory0.create(ERROR); DiagnosticFactory0 NULLABLE_ON_DEFINITELY_NOT_NULLABLE = DiagnosticFactory0.create(ERROR); + DiagnosticFactory0 INCORRECT_LEFT_COMPONENT_OF_INTERSECTION = DiagnosticFactory0.create(ERROR); + DiagnosticFactory0 INCORRECT_RIGHT_COMPONENT_OF_INTERSECTION = DiagnosticFactory0.create(ERROR); DiagnosticFactory2 WRONG_NUMBER_OF_TYPE_ARGUMENTS = DiagnosticFactory2.create(ERROR); DiagnosticFactory1 OUTER_CLASS_ARGUMENTS_REQUIRED = DiagnosticFactory1.create(ERROR); DiagnosticFactory1 TYPE_ARGUMENTS_NOT_ALLOWED = DiagnosticFactory1.create(ERROR); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java index 44ebc73fa3e..2eefa8f8305 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java @@ -696,6 +696,8 @@ public class DefaultErrorMessages { MAP.put(REDUNDANT_NULLABLE, "Redundant '?'"); MAP.put(DEFINITELY_NOT_NULLABLE_NOT_APPLICABLE, "'!!' is only applicable to type parameters with nullable upper bounds"); MAP.put(NULLABLE_ON_DEFINITELY_NOT_NULLABLE, "'!!' type cannot be marked as nullable"); + MAP.put(INCORRECT_LEFT_COMPONENT_OF_INTERSECTION, "Intersection types are only supported for definitely non-nullable types: left part should be a type parameter with nullable bounds"); + MAP.put(INCORRECT_RIGHT_COMPONENT_OF_INTERSECTION, "Intersection types are only supported for definitely non-nullable types: right part should be non-nullable Any"); MAP.put(UNSAFE_CALL, "Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type {0}", RENDER_TYPE); MAP.put(UNSAFE_IMPLICIT_INVOKE_CALL, "Reference has a nullable type ''{0}'', use explicit ''?.invoke()'' to make a function-like call instead", RENDER_TYPE); MAP.put(AMBIGUOUS_LABEL, "Ambiguous label"); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/TypeResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/TypeResolver.kt index a04ca367424..dbd4f4a8883 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/TypeResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/TypeResolver.kt @@ -55,9 +55,7 @@ import org.jetbrains.kotlin.resolve.source.getPsi import org.jetbrains.kotlin.resolve.source.toSourceElement import org.jetbrains.kotlin.types.* import org.jetbrains.kotlin.types.Variance.* -import org.jetbrains.kotlin.types.typeUtil.containsTypeAliasParameters -import org.jetbrains.kotlin.types.typeUtil.containsTypeAliases -import org.jetbrains.kotlin.types.typeUtil.isArrayOfNothing +import org.jetbrains.kotlin.types.typeUtil.* import org.jetbrains.kotlin.utils.addToStdlib.safeAs import kotlin.math.min @@ -319,6 +317,57 @@ class TypeResolver( result = type(definitelyNotNullKotlinType) } + override fun visitIntersectionType(intersectionType: KtIntersectionType) { + val leftType = resolvePossiblyBareType(c, intersectionType.getLeftTypeRef() ?: return).let { + when { + it.isBare -> error("There should not be bare types for intersections") + else -> it.actualType + } + } + + // Just in case of early return + result = type(leftType) + + val rightType = resolvePossiblyBareType(c, intersectionType.getRightTypeRef() ?: return).let { + when { + it.isBare -> error("There should not be bare types for intersections") + else -> it.actualType + } + } + + if (!languageVersionSettings.supportsFeature(LanguageFeature.DefinitelyNotNullTypeParameters)) { + c.trace.report( + UNSUPPORTED_FEATURE.on( + intersectionType, + LanguageFeature.DefinitelyNotNullTypeParameters to languageVersionSettings + ) + ) + return + } + + if (!leftType.isTypeParameter() || leftType.isMarkedNullable || !TypeUtils.isNullableType(leftType)) { + c.trace.report(INCORRECT_LEFT_COMPONENT_OF_INTERSECTION.on(intersectionType.getLeftTypeRef()!!)) + return + } + + if (!rightType.isAny()) { + c.trace.report(INCORRECT_RIGHT_COMPONENT_OF_INTERSECTION.on(intersectionType.getRightTypeRef()!!)) + return + } + + val definitelyNotNullType = + DefinitelyNotNullType.makeDefinitelyNotNull(leftType.unwrap()) + ?: error( + "Definitely not-nullable type is not created for type parameter with nullable upper bound ${ + TypeUtils.getTypeParameterDescriptorOrNull( + leftType + )!! + }" + ) + + result = type(definitelyNotNullType) + } + override fun visitFunctionType(type: KtFunctionType) { val receiverTypeRef = type.receiverTypeReference val receiverType = if (receiverTypeRef == null) null else resolveType(c.noBareTypes(), receiverTypeRef) diff --git a/compiler/psi/src/org/jetbrains/kotlin/KtNodeTypes.java b/compiler/psi/src/org/jetbrains/kotlin/KtNodeTypes.java index 35e59102d24..70b6852b9ba 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/KtNodeTypes.java +++ b/compiler/psi/src/org/jetbrains/kotlin/KtNodeTypes.java @@ -76,6 +76,7 @@ public interface KtNodeTypes { IElementType FUNCTION_TYPE_RECEIVER = KtStubElementTypes.FUNCTION_TYPE_RECEIVER; IElementType NULLABLE_TYPE = KtStubElementTypes.NULLABLE_TYPE; IElementType DEFINITELY_NOT_NULL_TYPE = KtStubElementTypes.DEFINITELY_NOT_NULL_TYPE; + IElementType INTERSECTION_TYPE = KtStubElementTypes.INTERSECTION_TYPE; IElementType TYPE_PROJECTION = KtStubElementTypes.TYPE_PROJECTION; IElementType PROPERTY_ACCESSOR = KtStubElementTypes.PROPERTY_ACCESSOR; diff --git a/compiler/psi/src/org/jetbrains/kotlin/parsing/KotlinExpressionParsing.java b/compiler/psi/src/org/jetbrains/kotlin/parsing/KotlinExpressionParsing.java index b77d8e7dc63..48639b9a9e0 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/parsing/KotlinExpressionParsing.java +++ b/compiler/psi/src/org/jetbrains/kotlin/parsing/KotlinExpressionParsing.java @@ -158,7 +158,7 @@ public class KotlinExpressionParsing extends AbstractKotlinParsing { AS(AS_KEYWORD, AS_SAFE) { @Override public IElementType parseRightHandSide(IElementType operation, KotlinExpressionParsing parser) { - parser.myKotlinParsing.parseTypeRefWithoutDefinitelyNotNull(); + parser.myKotlinParsing.parseTypeRefWithoutIntersections(); return BINARY_WITH_TYPE; } @@ -177,7 +177,7 @@ public class KotlinExpressionParsing extends AbstractKotlinParsing { @Override public IElementType parseRightHandSide(IElementType operation, KotlinExpressionParsing parser) { if (operation == IS_KEYWORD || operation == NOT_IS) { - parser.myKotlinParsing.parseTypeRefWithoutDefinitelyNotNull(); + parser.myKotlinParsing.parseTypeRefWithoutIntersections(); return IS_EXPRESSION; } diff --git a/compiler/psi/src/org/jetbrains/kotlin/parsing/KotlinParsing.java b/compiler/psi/src/org/jetbrains/kotlin/parsing/KotlinParsing.java index cac71af60bf..f0f95238887 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/parsing/KotlinParsing.java +++ b/compiler/psi/src/org/jetbrains/kotlin/parsing/KotlinParsing.java @@ -833,7 +833,7 @@ public class KotlinParsing extends AbstractKotlinParsing { PsiBuilder.Marker reference = mark(); PsiBuilder.Marker typeReference = mark(); - parseUserType(/* allowNotNullTypeParameter */ false); + parseUserType(/* allowSimpleIntersectionTypes */ false); typeReference.done(TYPE_REFERENCE); reference.done(CONSTRUCTOR_CALLEE); @@ -1713,7 +1713,7 @@ public class KotlinParsing extends AbstractKotlinParsing { if (!receiverPresent) return false; - createTruncatedBuilder(lastDot).parseTypeRef(); + createTruncatedBuilder(lastDot).parseTypeRefWithoutIntersections(); if (atSet(RECEIVER_TYPE_TERMINATORS)) { advance(); // expectation @@ -2055,22 +2055,22 @@ public class KotlinParsing extends AbstractKotlinParsing { parseTypeRef(TokenSet.EMPTY); } - void parseTypeRefWithoutDefinitelyNotNull() { - parseTypeRef(TokenSet.EMPTY, /* allowNotNullTypeParameters */ false); + void parseTypeRefWithoutIntersections() { + parseTypeRef(TokenSet.EMPTY, /* allowSimpleIntersectionTypes */ false); } void parseTypeRef(TokenSet extraRecoverySet) { - parseTypeRef(extraRecoverySet, /* allowNotNullTypeParameters */ true); + parseTypeRef(extraRecoverySet, /* allowSimpleIntersectionTypes */ true); } - private void parseTypeRef(TokenSet extraRecoverySet, boolean allowNotNullTypeParameters) { - PsiBuilder.Marker typeRefMarker = parseTypeRefContents(extraRecoverySet, allowNotNullTypeParameters); + private void parseTypeRef(TokenSet extraRecoverySet, boolean allowSimpleIntersectionTypes) { + PsiBuilder.Marker typeRefMarker = parseTypeRefContents(extraRecoverySet, allowSimpleIntersectionTypes); typeRefMarker.done(TYPE_REFERENCE); } // The extraRecoverySet is needed for the foo(bar(z)) case, to tell whether we should stop // on expression-indicating symbols or not - private PsiBuilder.Marker parseTypeRefContents(TokenSet extraRecoverySet, boolean allowNotNullTypeParameters) { + private PsiBuilder.Marker parseTypeRefContents(TokenSet extraRecoverySet, boolean allowSimpleIntersectionTypes) { PsiBuilder.Marker typeRefMarker = mark(); parseTypeModifierList(); @@ -2086,14 +2086,14 @@ public class KotlinParsing extends AbstractKotlinParsing { dynamicType.done(DYNAMIC_TYPE); } else if (at(IDENTIFIER) || at(PACKAGE_KEYWORD) || atParenthesizedMutableForPlatformTypes(0)) { - parseUserType(allowNotNullTypeParameters); + parseUserType(allowSimpleIntersectionTypes); } else if (at(LPAR)) { PsiBuilder.Marker functionOrParenthesizedType = mark(); // This may be a function parameter list or just a parenthesized type advance(); // LPAR - parseTypeRefContents(TokenSet.EMPTY, allowNotNullTypeParameters).drop(); // parenthesized types, no reference element around it is needed + parseTypeRefContents(TokenSet.EMPTY, /* allowSimpleIntersectionTypes */ true).drop(); // parenthesized types, no reference element around it is needed if (at(RPAR)) { advance(); // RPAR @@ -2133,7 +2133,23 @@ public class KotlinParsing extends AbstractKotlinParsing { typeElementMarker = parseNullableTypeSuffix(typeElementMarker); myBuilder.restoreJoiningComplexTokensState(); - if (typeBeforeDot && at(DOT)) { + boolean wasIntersection = false; + if (allowSimpleIntersectionTypes && at(AND)) { + PsiBuilder.Marker leftTypeRef = typeElementMarker; + + typeElementMarker = typeElementMarker.precede(); + PsiBuilder.Marker intersectionType = leftTypeRef.precede(); + + leftTypeRef.done(TYPE_REFERENCE); + + advance(); // & + parseTypeRef(extraRecoverySet, /* allowSimpleIntersectionTypes */ true); + + intersectionType.done(INTERSECTION_TYPE); + wasIntersection = true; + } + + if (typeBeforeDot && !wasIntersection && at(DOT)) { // This is a receiver for a function type // A.(B) -> C // ^ @@ -2183,7 +2199,7 @@ public class KotlinParsing extends AbstractKotlinParsing { * - (Mutable)List! * - Array<(out) Foo>! */ - private void parseUserType(boolean allowNotNullTypeParameter) { + private void parseUserType(boolean allowSimpleIntersectionTypes) { PsiBuilder.Marker userType = mark(); if (at(PACKAGE_KEYWORD)) { @@ -2228,12 +2244,6 @@ public class KotlinParsing extends AbstractKotlinParsing { } userType.done(USER_TYPE); - - if (allowNotNullTypeParameter && at(EXCLEXCL)) { - PsiBuilder.Marker definitelyNotNull = userType.precede(); - advance(); // !! - definitelyNotNull.done(DEFINITELY_NOT_NULL_TYPE); - } } private boolean atParenthesizedMutableForPlatformTypes(int offset) { diff --git a/compiler/psi/src/org/jetbrains/kotlin/psi/KtIntersectionType.kt b/compiler/psi/src/org/jetbrains/kotlin/psi/KtIntersectionType.kt new file mode 100644 index 00000000000..8a8e159fe63 --- /dev/null +++ b/compiler/psi/src/org/jetbrains/kotlin/psi/KtIntersectionType.kt @@ -0,0 +1,24 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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.psi + +import com.intellij.lang.ASTNode +import org.jetbrains.kotlin.psi.stubs.KotlinPlaceHolderStub +import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes + +class KtIntersectionType : KtElementImplStub>, KtTypeElement { + constructor(node: ASTNode) : super(node) + constructor(stub: KotlinPlaceHolderStub) : super(stub, KtStubElementTypes.INTERSECTION_TYPE) + + override fun getTypeArgumentsAsTypes(): List = emptyList() + + fun getLeftTypeRef(): KtTypeReference? = getStubOrPsiChildrenAsList(KtStubElementTypes.TYPE_REFERENCE).getOrNull(0) + fun getRightTypeRef(): KtTypeReference? = getStubOrPsiChildrenAsList(KtStubElementTypes.TYPE_REFERENCE).getOrNull(1) + + override fun accept(visitor: KtVisitor, data: D): R { + return visitor.visitIntersectionType(this, data) + } +} diff --git a/compiler/psi/src/org/jetbrains/kotlin/psi/KtVisitor.java b/compiler/psi/src/org/jetbrains/kotlin/psi/KtVisitor.java index b2da4ff30f4..414c398bd52 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/psi/KtVisitor.java +++ b/compiler/psi/src/org/jetbrains/kotlin/psi/KtVisitor.java @@ -406,6 +406,10 @@ public class KtVisitor extends PsiElementVisitor { return visitTypeElement(definitelyNotNullType, data); } + public R visitIntersectionType(@NotNull KtIntersectionType definitelyNotNullType, D data) { + return visitTypeElement(definitelyNotNullType, data); + } + public R visitTypeProjection(@NotNull KtTypeProjection typeProjection, D data) { return visitKtElement(typeProjection, data); } diff --git a/compiler/psi/src/org/jetbrains/kotlin/psi/KtVisitorVoid.java b/compiler/psi/src/org/jetbrains/kotlin/psi/KtVisitorVoid.java index 0ff6bc09f9f..5c055d0a34f 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/psi/KtVisitorVoid.java +++ b/compiler/psi/src/org/jetbrains/kotlin/psi/KtVisitorVoid.java @@ -389,6 +389,10 @@ public class KtVisitorVoid extends KtVisitor { super.visitDefinitelyNotNullType(definitelyNotNullType, null); } + public void visitIntersectionType(@NotNull KtIntersectionType intersectionType) { + super.visitIntersectionType(intersectionType, null); + } + public void visitTypeProjection(@NotNull KtTypeProjection typeProjection) { super.visitTypeProjection(typeProjection, null); } @@ -982,6 +986,12 @@ public class KtVisitorVoid extends KtVisitor { return null; } + @Override + public Void visitIntersectionType(@NotNull KtIntersectionType intersectionType, Void data) { + visitIntersectionType(intersectionType); + return null; + } + @Override public final Void visitTypeProjection(@NotNull KtTypeProjection typeProjection, Void data) { visitTypeProjection(typeProjection); diff --git a/compiler/psi/src/org/jetbrains/kotlin/psi/stubs/elements/KtStubElementTypes.java b/compiler/psi/src/org/jetbrains/kotlin/psi/stubs/elements/KtStubElementTypes.java index 92c79d55f1c..10ad604a307 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/psi/stubs/elements/KtStubElementTypes.java +++ b/compiler/psi/src/org/jetbrains/kotlin/psi/stubs/elements/KtStubElementTypes.java @@ -82,6 +82,9 @@ public interface KtStubElementTypes { KtPlaceHolderStubElementType DEFINITELY_NOT_NULL_TYPE = new KtPlaceHolderStubElementType<>("DEFINITELY_NOT_NULL_TYPE", KtDefinitelyNotNullType.class); + KtPlaceHolderStubElementType INTERSECTION_TYPE = + new KtPlaceHolderStubElementType<>("INTERSECTION_TYPE", KtIntersectionType.class); + KtPlaceHolderStubElementType TYPE_REFERENCE = new KtPlaceHolderStubElementType<>("TYPE_REFERENCE", KtTypeReference.class); @@ -170,7 +173,7 @@ public interface KtStubElementTypes { TokenSet SUPER_TYPE_LIST_ENTRIES = TokenSet.create(DELEGATED_SUPER_TYPE_ENTRY, SUPER_TYPE_CALL_ENTRY, SUPER_TYPE_ENTRY); - TokenSet TYPE_ELEMENT_TYPES = TokenSet.create(USER_TYPE, NULLABLE_TYPE, FUNCTION_TYPE, DYNAMIC_TYPE, DEFINITELY_NOT_NULL_TYPE); + TokenSet TYPE_ELEMENT_TYPES = TokenSet.create(USER_TYPE, NULLABLE_TYPE, FUNCTION_TYPE, DYNAMIC_TYPE, INTERSECTION_TYPE); TokenSet INSIDE_DIRECTIVE_EXPRESSIONS = TokenSet.create(REFERENCE_EXPRESSION, DOT_QUALIFIED_EXPRESSION); } diff --git a/compiler/testData/codegen/box/notNullAssertions/definitelyNotNullTypes.kt b/compiler/testData/codegen/box/notNullAssertions/definitelyNotNullTypes.kt index 2fd8038e73a..86eff0ac1ef 100644 --- a/compiler/testData/codegen/box/notNullAssertions/definitelyNotNullTypes.kt +++ b/compiler/testData/codegen/box/notNullAssertions/definitelyNotNullTypes.kt @@ -17,7 +17,7 @@ public abstract class JClass { // FILE: main.kt class KDerived : JClass() { - override fun foo(e: E!!) { + override fun foo(e: E & Any) { throw RuntimeException("Should not be called") } } diff --git a/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/approximation.fir.kt b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/approximation.fir.kt new file mode 100644 index 00000000000..a5545ad4bb4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/approximation.fir.kt @@ -0,0 +1,14 @@ +// !LANGUAGE: +DefinitelyNotNullTypeParameters + +fun foo(x: T, y: T & Any) = x!! + +fun main() { + foo("", "").length + foo("", null).length + foo(null, "").length + foo(null, null).length + + foo("", "").length + foo("", null).length + foo(null, "").length +} diff --git a/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/approximation.kt b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/approximation.kt new file mode 100644 index 00000000000..2ceb96bda8d --- /dev/null +++ b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/approximation.kt @@ -0,0 +1,14 @@ +// !LANGUAGE: +DefinitelyNotNullTypeParameters + +fun foo(x: T, y: T & Any) = x!! + +fun main() { + foo("", "").length + foo("", null).length + foo(null, "").length + foo(null, null).length + + foo("", "").length + foo("", null).length + foo(null, "").length +} diff --git a/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/approximation.txt b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/approximation.txt new file mode 100644 index 00000000000..2292cfca4ef --- /dev/null +++ b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/approximation.txt @@ -0,0 +1,5 @@ +package + +public fun foo(/*0*/ x: T, /*1*/ y: T!!): T!! +public fun main(): kotlin.Unit + diff --git a/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/bareTypes.fir.kt b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/bareTypes.fir.kt new file mode 100644 index 00000000000..ab7716a9e4e --- /dev/null +++ b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/bareTypes.fir.kt @@ -0,0 +1,7 @@ +// !LANGUAGE: +DefinitelyNotNullTypeParameters + +fun main(x: Collection) { + if (x is List & Any) {} + + val w: List & Any = null!! +} diff --git a/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/bareTypes.kt b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/bareTypes.kt new file mode 100644 index 00000000000..70336680985 --- /dev/null +++ b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/bareTypes.kt @@ -0,0 +1,7 @@ +// !LANGUAGE: +DefinitelyNotNullTypeParameters + +fun main(x: Collection) { + if (x is List & Any) {} + + val w: List & Any = null!! +} diff --git a/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/bareTypes.txt b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/bareTypes.txt new file mode 100644 index 00000000000..2fb2114de6c --- /dev/null +++ b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/bareTypes.txt @@ -0,0 +1,3 @@ +package + +public fun main(/*0*/ x: kotlin.collections.Collection): kotlin.Unit diff --git a/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/disabledFeature.fir.kt b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/disabledFeature.fir.kt new file mode 100644 index 00000000000..04a1a02dccf --- /dev/null +++ b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/disabledFeature.fir.kt @@ -0,0 +1,3 @@ +// !LANGUAGE: -DefinitelyNotNullTypeParameters + +fun foo(x: T, y: T & Any): List? = null diff --git a/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/disabledFeature.kt b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/disabledFeature.kt new file mode 100644 index 00000000000..371d6a95279 --- /dev/null +++ b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/disabledFeature.kt @@ -0,0 +1,3 @@ +// !LANGUAGE: -DefinitelyNotNullTypeParameters + +fun foo(x: T, y: T & Any): List<T & Any>? = null diff --git a/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/disabledFeature.txt b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/disabledFeature.txt new file mode 100644 index 00000000000..c2e285b6fba --- /dev/null +++ b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/disabledFeature.txt @@ -0,0 +1,3 @@ +package + +public fun foo(/*0*/ x: T, /*1*/ y: T): kotlin.collections.List? diff --git a/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/inference.fir.kt b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/inference.fir.kt new file mode 100644 index 00000000000..d7550ccee36 --- /dev/null +++ b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/inference.fir.kt @@ -0,0 +1,33 @@ +// !LANGUAGE: +DefinitelyNotNullTypeParameters + +fun toDefNotNull(s: T): T & Any = s!! + +fun removeQuestionMark(x: K?): K = x!! + +fun Any.foo() {} + +fun expectNN(e: E & Any) {} + +fun main(x: F, y: F, z: F, w: F, m: F) { + val y1 = toDefNotNull(x) // K instead of K & Any + val y2: F & Any = toDefNotNull(x) // K instead of K & Any + val x1 = removeQuestionMark(x) // T or T & Any + val x2: F & Any = removeQuestionMark(x) // T or T & Any + + val z1 = x!! + val z2: F & Any = y!! + val w1 = if (z != null) z else return + val w2: F & Any = if (w != null) w else return + + y1.foo() + y2.foo() + x1.foo() + x2.foo() + z1.foo() + z2.foo() + w1.foo() + w2.foo() + + expectNN(m) + expectNN(m!!) +} diff --git a/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/inference.kt b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/inference.kt new file mode 100644 index 00000000000..0b26b2d9119 --- /dev/null +++ b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/inference.kt @@ -0,0 +1,33 @@ +// !LANGUAGE: +DefinitelyNotNullTypeParameters + +fun toDefNotNull(s: T): T & Any = s!! + +fun removeQuestionMark(x: K?): K = x!! + +fun Any.foo() {} + +fun expectNN(e: E & Any) {} + +fun main(x: F, y: F, z: F, w: F, m: F) { + val y1 = toDefNotNull(x) // K instead of K & Any + val y2: F & Any = toDefNotNull(x) // K instead of K & Any + val x1 = removeQuestionMark(x) // T or T & Any + val x2: F & Any = removeQuestionMark(x) // T or T & Any + + val z1 = x!! + val z2: F & Any = y!! + val w1 = if (z != null) z else return + val w2: F & Any = if (w != null) w else return + + y1.foo() + y2.foo() + x1.foo() + x2.foo() + z1.foo() + z2.foo() + w1.foo() + w2.foo() + + expectNN(m) + expectNN(m!!) +} diff --git a/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/inference.txt b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/inference.txt new file mode 100644 index 00000000000..b41a53165e8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/inference.txt @@ -0,0 +1,7 @@ +package + +public fun expectNN(/*0*/ e: E!!): kotlin.Unit +public fun main(/*0*/ x: F, /*1*/ y: F, /*2*/ z: F, /*3*/ w: F, /*4*/ m: F): kotlin.Unit +public fun removeQuestionMark(/*0*/ x: K?): K +public fun toDefNotNull(/*0*/ s: T): T!! +public fun kotlin.Any.foo(): kotlin.Unit diff --git a/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/isAsOperators.kt b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/isAsOperators.kt new file mode 100644 index 00000000000..c9e81d0b379 --- /dev/null +++ b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/isAsOperators.kt @@ -0,0 +1,17 @@ +// FIR_IDENTICAL +// SKIP_TXT +// !LANGUAGE: -DefinitelyNotNullTypeParameters + +fun Any.bar() {} +fun Boolean.baz() {} + +var x: Int = 0 + +inline fun foo(v: Any?): T { + if (x > 0) 1 else v as T & Any + if (x > 1) 2 else v as? T & Any + if (x > 2) 3 else v is T & Any + if (x > 3) 4 else v !is T & Any + + return v as T & Any +} diff --git a/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/isAsOperatorsEnabled.kt b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/isAsOperatorsEnabled.kt new file mode 100644 index 00000000000..cbc1fff53b1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/isAsOperatorsEnabled.kt @@ -0,0 +1,17 @@ +// FIR_IDENTICAL +// SKIP_TXT +// !LANGUAGE: +DefinitelyNotNullTypeParameters + +fun Any.bar() {} +fun Boolean.baz() {} + +var x: Int = 0 + +inline fun foo(v: Any?): T { + if (x > 0) 1 else v as T & Any + if (x > 1) 2 else v as? T & Any + if (x > 2) 3 else v is T & Any + if (x > 3) 4 else v !is T & Any + + return v as T & Any +} diff --git a/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/notApplicable.fir.kt b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/notApplicable.fir.kt new file mode 100644 index 00000000000..3f07a15bcd3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/notApplicable.fir.kt @@ -0,0 +1,18 @@ +// !LANGUAGE: +DefinitelyNotNullTypeParameters + +fun foo(x: T & Any, y: List & Any) {} + +fun bar1(x: F? & Any) {} +fun bar2(x: F & Any?) {} +fun bar3(x: (F?) & Any) {} +fun bar4(x: (F & Any)?) {} + +fun bar5(x: F & String) {} + +fun bar6(x: F & (F & Any)) {} +fun bar7(x: (F & Any) & Any) {} +fun bar8(x: (F & Any).() -> Unit) {} +fun (F & Any).bar9(x: () -> Unit) {} + +fun bar10(x: F & Any & String) {} +fun bar11(x: Double & Any & String) {} diff --git a/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/notApplicable.kt b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/notApplicable.kt new file mode 100644 index 00000000000..f39370431df --- /dev/null +++ b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/notApplicable.kt @@ -0,0 +1,18 @@ +// !LANGUAGE: +DefinitelyNotNullTypeParameters + +fun foo(x: T & Any, y: List<String & Any> & Any) {} + +fun bar1(x: F? & Any) {} +fun bar2(x: F & Any?) {} +fun bar3(x: (F?) & Any) {} +fun bar4(x: (F & Any)?) {} + +fun bar5(x: F & String) {} + +fun bar6(x: F & (F & Any)) {} +fun bar7(x: (F & Any) & Any) {} +fun bar8(x: (F & Any).() -> Unit) {} +fun (F & Any).bar9(x: () -> Unit) {} + +fun bar10(x: F & Any & String) {} +fun bar11(x: Double & Any & String) {} diff --git a/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/notApplicable.txt b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/notApplicable.txt new file mode 100644 index 00000000000..84f2eb14186 --- /dev/null +++ b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/notApplicable.txt @@ -0,0 +1,15 @@ +package + +public fun bar1(/*0*/ x: F?): kotlin.Unit +public fun bar10(/*0*/ x: F & Any): kotlin.Unit +public fun bar11(/*0*/ x: kotlin.Double): kotlin.Unit +public fun bar2(/*0*/ x: F): kotlin.Unit +public fun bar3(/*0*/ x: F?): kotlin.Unit +public fun bar4(/*0*/ x: F?): kotlin.Unit +public fun bar5(/*0*/ x: F): kotlin.Unit +public fun bar6(/*0*/ x: F): kotlin.Unit +public fun bar7(/*0*/ x: F!!): kotlin.Unit +public fun bar8(/*0*/ x: F!!.() -> kotlin.Unit): kotlin.Unit +public fun foo(/*0*/ x: T, /*1*/ y: kotlin.collections.List): kotlin.Unit +public fun F!!.bar9(/*0*/ x: () -> kotlin.Unit): kotlin.Unit + diff --git a/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/overrides.fir.kt b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/overrides.fir.kt new file mode 100644 index 00000000000..49315e5a812 --- /dev/null +++ b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/overrides.fir.kt @@ -0,0 +1,36 @@ +// !LANGUAGE: +DefinitelyNotNullTypeParameters + +interface A { + fun foo(x: T): T + fun bar(x: T & Any): T & Any +} + +interface B : A { + override fun foo(x: T1): T1 + override fun bar(x: T1 & Any): T1 & Any +} + +interface C : A { + override fun foo(x: T2 & Any): T2 & Any + override fun bar(x: T2): T2 +} + +interface D : A { + override fun foo(x: String?): String? + override fun bar(x: String): String +} + +interface E : A { + override fun foo(x: String): String + override fun bar(x: String): String +} + +interface F : A { + override fun foo(x: String): String + override fun bar(x: String?): String? +} + +interface G : A { + override fun foo(x: T3): T3 + override fun bar(x: T3): T3 +} diff --git a/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/overrides.kt b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/overrides.kt new file mode 100644 index 00000000000..44c1eaefe9c --- /dev/null +++ b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/overrides.kt @@ -0,0 +1,36 @@ +// !LANGUAGE: +DefinitelyNotNullTypeParameters + +interface A { + fun foo(x: T): T + fun bar(x: T & Any): T & Any +} + +interface B : A { + override fun foo(x: T1): T1 + override fun bar(x: T1 & Any): T1 & Any +} + +interface C : A { + override fun foo(x: T2 & Any): T2 & Any + override fun bar(x: T2): T2 +} + +interface D : A { + override fun foo(x: String?): String? + override fun bar(x: String): String +} + +interface E : A { + override fun foo(x: String): String + override fun bar(x: String): String +} + +interface F : A { + override fun foo(x: String): String + override fun bar(x: String?): String? +} + +interface G : A { + override fun foo(x: T3): T3 + override fun bar(x: T3): T3 +} diff --git a/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/overrides.txt b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/overrides.txt new file mode 100644 index 00000000000..50b2bc774ec --- /dev/null +++ b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/overrides.txt @@ -0,0 +1,61 @@ +package + +public interface A { + public abstract fun bar(/*0*/ x: T!!): T!! + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public abstract fun foo(/*0*/ x: T): T + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface B : A { + public abstract override /*1*/ fun bar(/*0*/ x: T1!!): T1!! + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public abstract override /*1*/ fun foo(/*0*/ x: T1): T1 + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface C : A { + public abstract fun bar(/*0*/ x: T2): T2 + public abstract override /*1*/ /*fake_override*/ fun bar(/*0*/ x: T2!!): T2!! + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public abstract override /*1*/ /*fake_override*/ fun foo(/*0*/ x: T2): T2 + public abstract fun foo(/*0*/ x: T2!!): T2!! + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface D : A { + public abstract override /*1*/ fun bar(/*0*/ x: kotlin.String): kotlin.String + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public abstract override /*1*/ fun foo(/*0*/ x: kotlin.String?): kotlin.String? + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface E : A { + public abstract override /*1*/ fun bar(/*0*/ x: kotlin.String): kotlin.String + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public abstract override /*1*/ fun foo(/*0*/ x: kotlin.String): kotlin.String + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface F : A { + public abstract override /*1*/ /*fake_override*/ fun bar(/*0*/ x: kotlin.String): kotlin.String + public abstract fun bar(/*0*/ x: kotlin.String?): kotlin.String? + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public abstract fun foo(/*0*/ x: kotlin.String): kotlin.String + public abstract override /*1*/ /*fake_override*/ fun foo(/*0*/ x: kotlin.String?): kotlin.String? + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface G : A { + public abstract override /*1*/ fun bar(/*0*/ x: T3): T3 + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public abstract override /*1*/ fun foo(/*0*/ x: T3): T3 + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/overridesJavaAnnotated.fir.kt b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/overridesJavaAnnotated.fir.kt new file mode 100644 index 00000000000..a945b91947e --- /dev/null +++ b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/overridesJavaAnnotated.fir.kt @@ -0,0 +1,42 @@ +// !LANGUAGE: +DefinitelyNotNullTypeParameters +ProhibitUsingNullableTypeParameterAgainstNotNullAnnotated + +// FILE: A.java +import org.jetbrains.annotations.*; + +public interface A { + public T foo(T x) { return x; } + @NotNull + public T bar(@NotNull T x) {} +} + +// FILE: main.kt + +interface B : A { + override fun foo(x: T1): T1 + override fun bar(x: T1 & Any): T1 & Any +} + +interface C : A { + override fun foo(x: T2 & Any): T2 & Any + override fun bar(x: T2): T2 +} + +interface D : A { + override fun foo(x: String?): String? + override fun bar(x: String): String +} + +interface E : A { + override fun foo(x: String): String + override fun bar(x: String): String +} + +interface F : A { + override fun foo(x: String): String + override fun bar(x: String?): String? +} + +interface G : A { + override fun foo(x: T3): T3 + override fun bar(x: T3): T3 +} diff --git a/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/overridesJavaAnnotated.kt b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/overridesJavaAnnotated.kt new file mode 100644 index 00000000000..182da4b4784 --- /dev/null +++ b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/overridesJavaAnnotated.kt @@ -0,0 +1,42 @@ +// !LANGUAGE: +DefinitelyNotNullTypeParameters +ProhibitUsingNullableTypeParameterAgainstNotNullAnnotated + +// FILE: A.java +import org.jetbrains.annotations.*; + +public interface A { + public T foo(T x) { return x; } + @NotNull + public T bar(@NotNull T x) {} +} + +// FILE: main.kt + +interface B : A { + override fun foo(x: T1): T1 + override fun bar(x: T1 & Any): T1 & Any +} + +interface C : A { + override fun foo(x: T2 & Any): T2 & Any + override fun bar(x: T2): T2 +} + +interface D : A { + override fun foo(x: String?): String? + override fun bar(x: String): String +} + +interface E : A { + override fun foo(x: String): String + override fun bar(x: String): String +} + +interface F : A { + override fun foo(x: String): String + override fun bar(x: String?): String? +} + +interface G : A { + override fun foo(x: T3): T3 + override fun bar(x: T3): T3 +} diff --git a/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/overridesJavaAnnotated.txt b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/overridesJavaAnnotated.txt new file mode 100644 index 00000000000..6c3f08fa065 --- /dev/null +++ b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/overridesJavaAnnotated.txt @@ -0,0 +1,61 @@ +package + +public interface A { + @org.jetbrains.annotations.NotNull public abstract fun bar(/*0*/ @org.jetbrains.annotations.NotNull x: T!!): T!! + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public abstract fun foo(/*0*/ x: T!): T! + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface B : A { + public abstract override /*1*/ fun bar(/*0*/ x: T1!!): T1!! + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public abstract override /*1*/ fun foo(/*0*/ x: T1): T1 + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface C : A { + public abstract fun bar(/*0*/ x: T2): T2 + @org.jetbrains.annotations.NotNull public abstract override /*1*/ /*fake_override*/ fun bar(/*0*/ @org.jetbrains.annotations.NotNull x: T2!!): T2!! + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public abstract override /*1*/ /*fake_override*/ fun foo(/*0*/ x: T2!): T2! + public abstract fun foo(/*0*/ x: T2!!): T2!! + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface D : A { + public abstract override /*1*/ fun bar(/*0*/ x: kotlin.String): kotlin.String + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public abstract override /*1*/ fun foo(/*0*/ x: kotlin.String?): kotlin.String? + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface E : A { + public abstract override /*1*/ fun bar(/*0*/ x: kotlin.String): kotlin.String + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public abstract override /*1*/ fun foo(/*0*/ x: kotlin.String): kotlin.String + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface F : A { + @org.jetbrains.annotations.NotNull public abstract override /*1*/ /*fake_override*/ fun bar(/*0*/ @org.jetbrains.annotations.NotNull x: kotlin.String): kotlin.String + public abstract fun bar(/*0*/ x: kotlin.String?): kotlin.String? + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public abstract fun foo(/*0*/ x: kotlin.String): kotlin.String + public abstract override /*1*/ /*fake_override*/ fun foo(/*0*/ x: kotlin.String?): kotlin.String? + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface G : A { + public abstract override /*1*/ fun bar(/*0*/ x: T3): T3 + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public abstract override /*1*/ fun foo(/*0*/ x: T3): T3 + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/simple.fir.kt b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/simple.fir.kt new file mode 100644 index 00000000000..cc2b09d8856 --- /dev/null +++ b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/simple.fir.kt @@ -0,0 +1,14 @@ +// !LANGUAGE: +DefinitelyNotNullTypeParameters + +fun foo(x: T, y: T & Any): T & Any = x ?: y + +fun main() { + foo("", "").length + foo("", null).length + foo(null, "").length + foo(null, null).length + + foo("", "").length + foo("", null).length + foo(null, "").length +} diff --git a/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/simple.kt b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/simple.kt new file mode 100644 index 00000000000..8653d41b72e --- /dev/null +++ b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/simple.kt @@ -0,0 +1,14 @@ +// !LANGUAGE: +DefinitelyNotNullTypeParameters + +fun foo(x: T, y: T & Any): T & Any = x ?: y + +fun main() { + foo("", "").length + foo("", null).length + foo(null, "").length + foo(null, null).length + + foo("", "").length + foo("", null).length + foo(null, "").length +} diff --git a/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/simple.txt b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/simple.txt new file mode 100644 index 00000000000..db1673f7a72 --- /dev/null +++ b/compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/simple.txt @@ -0,0 +1,4 @@ +package + +public fun foo(/*0*/ x: T, /*1*/ y: T!!): T!! +public fun main(): kotlin.Unit diff --git a/compiler/testData/loadJava/compiledKotlin/annotations/types/DefinitelyNotNull.kt b/compiler/testData/loadJava/compiledKotlin/annotations/types/DefinitelyNotNull.kt index 0064ff6484e..64e81e3ba35 100644 --- a/compiler/testData/loadJava/compiledKotlin/annotations/types/DefinitelyNotNull.kt +++ b/compiler/testData/loadJava/compiledKotlin/annotations/types/DefinitelyNotNull.kt @@ -2,4 +2,4 @@ // COMPILER_ARGUMENTS: -XXLanguage:+DefinitelyNotNullTypeParameters package test -fun foo(x: T!!, y: List, z: (T!!) -> T!!): T!! = x +fun foo(x: T & Any, y: List, z: (T & Any) -> T & Any): T & Any = x diff --git a/compiler/testData/psi/AnnotatedIntersections.kt b/compiler/testData/psi/AnnotatedIntersections.kt new file mode 100644 index 00000000000..b2b1149bea0 --- /dev/null +++ b/compiler/testData/psi/AnnotatedIntersections.kt @@ -0,0 +1,10 @@ +fun foo1(x: @ann T & Any) {} +fun foo2(x: List<@ann T & Any>) {} +fun foo3(x: List) {} +fun foo4(x: @ann (T & Any)) {} +fun foo5(x: @ann T? & Any?) {} +fun foo6(x: @ann T & Any & Any) {} +fun foo7(x: @ann T & (Any & Any)) {} +fun @ann (T & Any).foo8() {} +fun foo10(x: @ann T & Any.() -> Unit) {} +fun foo11(x: @ann (T & Any).() -> Unit) {} diff --git a/compiler/testData/psi/AnnotatedIntersections.txt b/compiler/testData/psi/AnnotatedIntersections.txt new file mode 100644 index 00000000000..7a7ff0cb5c5 --- /dev/null +++ b/compiler/testData/psi/AnnotatedIntersections.txt @@ -0,0 +1,523 @@ +KtFile: AnnotatedIntersections.kt + PACKAGE_DIRECTIVE + + IMPORT_LIST + + FUN + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + TYPE_PARAMETER_LIST + PsiElement(LT)('<') + TYPE_PARAMETER + PsiElement(IDENTIFIER)('T') + PsiElement(GT)('>') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo1') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + VALUE_PARAMETER + PsiElement(IDENTIFIER)('x') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + MODIFIER_LIST + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('ann') + PsiWhiteSpace(' ') + INTERSECTION_TYPE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('T') + PsiWhiteSpace(' ') + PsiElement(AND)('&') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Any') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n') + FUN + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + TYPE_PARAMETER_LIST + PsiElement(LT)('<') + TYPE_PARAMETER + PsiElement(IDENTIFIER)('T') + PsiElement(GT)('>') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo2') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + VALUE_PARAMETER + PsiElement(IDENTIFIER)('x') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('List') + TYPE_ARGUMENT_LIST + PsiElement(LT)('<') + TYPE_PROJECTION + TYPE_REFERENCE + MODIFIER_LIST + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('ann') + PsiWhiteSpace(' ') + INTERSECTION_TYPE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('T') + PsiWhiteSpace(' ') + PsiElement(AND)('&') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Any') + PsiElement(GT)('>') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n') + FUN + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + TYPE_PARAMETER_LIST + PsiElement(LT)('<') + TYPE_PARAMETER + PsiElement(IDENTIFIER)('T') + PsiElement(GT)('>') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo3') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + VALUE_PARAMETER + PsiElement(IDENTIFIER)('x') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('List') + TYPE_ARGUMENT_LIST + PsiElement(LT)('<') + TYPE_PROJECTION + MODIFIER_LIST + PsiElement(out)('out') + PsiWhiteSpace(' ') + TYPE_REFERENCE + MODIFIER_LIST + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('ann') + PsiWhiteSpace(' ') + INTERSECTION_TYPE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('T') + PsiWhiteSpace(' ') + PsiElement(AND)('&') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Any') + PsiElement(GT)('>') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n') + FUN + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + TYPE_PARAMETER_LIST + PsiElement(LT)('<') + TYPE_PARAMETER + PsiElement(IDENTIFIER)('T') + PsiElement(GT)('>') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo4') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + VALUE_PARAMETER + PsiElement(IDENTIFIER)('x') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + MODIFIER_LIST + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('ann') + PsiWhiteSpace(' ') + PsiElement(LPAR)('(') + INTERSECTION_TYPE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('T') + PsiWhiteSpace(' ') + PsiElement(AND)('&') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Any') + PsiElement(RPAR)(')') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n') + FUN + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + TYPE_PARAMETER_LIST + PsiElement(LT)('<') + TYPE_PARAMETER + PsiElement(IDENTIFIER)('T') + PsiElement(GT)('>') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo5') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + VALUE_PARAMETER + PsiElement(IDENTIFIER)('x') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + MODIFIER_LIST + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('ann') + PsiWhiteSpace(' ') + INTERSECTION_TYPE + TYPE_REFERENCE + NULLABLE_TYPE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('T') + PsiElement(QUEST)('?') + PsiWhiteSpace(' ') + PsiElement(AND)('&') + PsiWhiteSpace(' ') + TYPE_REFERENCE + NULLABLE_TYPE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Any') + PsiElement(QUEST)('?') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n') + FUN + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + TYPE_PARAMETER_LIST + PsiElement(LT)('<') + TYPE_PARAMETER + PsiElement(IDENTIFIER)('T') + PsiElement(GT)('>') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo6') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + VALUE_PARAMETER + PsiElement(IDENTIFIER)('x') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + MODIFIER_LIST + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('ann') + PsiWhiteSpace(' ') + INTERSECTION_TYPE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('T') + PsiWhiteSpace(' ') + PsiElement(AND)('&') + PsiWhiteSpace(' ') + TYPE_REFERENCE + INTERSECTION_TYPE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Any') + PsiWhiteSpace(' ') + PsiElement(AND)('&') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Any') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n') + FUN + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + TYPE_PARAMETER_LIST + PsiElement(LT)('<') + TYPE_PARAMETER + PsiElement(IDENTIFIER)('T') + PsiElement(GT)('>') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo7') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + VALUE_PARAMETER + PsiElement(IDENTIFIER)('x') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + MODIFIER_LIST + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('ann') + PsiWhiteSpace(' ') + INTERSECTION_TYPE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('T') + PsiWhiteSpace(' ') + PsiElement(AND)('&') + PsiWhiteSpace(' ') + TYPE_REFERENCE + PsiElement(LPAR)('(') + INTERSECTION_TYPE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Any') + PsiWhiteSpace(' ') + PsiElement(AND)('&') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Any') + PsiElement(RPAR)(')') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n') + FUN + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + TYPE_PARAMETER_LIST + PsiElement(LT)('<') + TYPE_PARAMETER + PsiElement(IDENTIFIER)('T') + PsiElement(GT)('>') + PsiWhiteSpace(' ') + PsiErrorElement:Annotations are not allowed in this position + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('ann') + PsiWhiteSpace(' ') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + VALUE_ARGUMENT + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('T') + PsiWhiteSpace(' ') + PsiErrorElement:Expecting ')' + PsiElement(AND)('&') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('Any') + PsiErrorElement:Expecting '(' + + PsiErrorElement:Expecting a top level declaration + PsiElement(RPAR)(')') + PsiErrorElement:Expecting a top level declaration + PsiElement(DOT)('.') + PsiErrorElement:Expecting a top level declaration + PsiElement(IDENTIFIER)('foo8') + PsiErrorElement:Expecting a top level declaration + PsiElement(LPAR)('(') + PsiErrorElement:Expecting a top level declaration + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + FUN + PsiErrorElement:Expecting a top level declaration + + BLOCK + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n') + FUN + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + TYPE_PARAMETER_LIST + PsiElement(LT)('<') + TYPE_PARAMETER + PsiElement(IDENTIFIER)('T') + PsiElement(GT)('>') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo10') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + VALUE_PARAMETER + PsiElement(IDENTIFIER)('x') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + MODIFIER_LIST + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('ann') + PsiWhiteSpace(' ') + INTERSECTION_TYPE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('T') + PsiWhiteSpace(' ') + PsiElement(AND)('&') + PsiWhiteSpace(' ') + TYPE_REFERENCE + FUNCTION_TYPE + FUNCTION_TYPE_RECEIVER + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Any') + PsiElement(DOT)('.') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + PsiElement(ARROW)('->') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Unit') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n') + FUN + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + TYPE_PARAMETER_LIST + PsiElement(LT)('<') + TYPE_PARAMETER + PsiElement(IDENTIFIER)('T') + PsiElement(GT)('>') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo11') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + VALUE_PARAMETER + PsiElement(IDENTIFIER)('x') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + MODIFIER_LIST + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('ann') + PsiWhiteSpace(' ') + FUNCTION_TYPE + FUNCTION_TYPE_RECEIVER + TYPE_REFERENCE + PsiElement(LPAR)('(') + INTERSECTION_TYPE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('T') + PsiWhiteSpace(' ') + PsiElement(AND)('&') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Any') + PsiElement(RPAR)(')') + PsiElement(DOT)('.') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + PsiElement(ARROW)('->') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Unit') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') \ No newline at end of file diff --git a/compiler/testData/psi/DefinitelyNotNullType.txt b/compiler/testData/psi/DefinitelyNotNullType.txt index c5a260822b9..2b7a21f4fb1 100644 --- a/compiler/testData/psi/DefinitelyNotNullType.txt +++ b/compiler/testData/psi/DefinitelyNotNullType.txt @@ -19,77 +19,75 @@ KtFile: DefinitelyNotNullType.kt PsiElement(IDENTIFIER)('x') PsiElement(COLON)(':') PsiWhiteSpace(' ') - TYPE_REFERENCE - DEFINITELY_NOT_NULL_TYPE - USER_TYPE - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('T') - PsiElement(EXCLEXCL)('!!') - PsiElement(COMMA)(',') - PsiWhiteSpace(' ') - VALUE_PARAMETER - PsiElement(IDENTIFIER)('y') - PsiElement(COLON)(':') - PsiWhiteSpace(' ') TYPE_REFERENCE USER_TYPE REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('List') - TYPE_ARGUMENT_LIST - PsiElement(LT)('<') - TYPE_PROJECTION - TYPE_REFERENCE - DEFINITELY_NOT_NULL_TYPE - USER_TYPE - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('T') - PsiElement(EXCLEXCL)('!!') - PsiElement(GT)('>') - PsiElement(COMMA)(',') - PsiWhiteSpace(' ') - VALUE_PARAMETER - PsiElement(IDENTIFIER)('z') - PsiElement(COLON)(':') - PsiWhiteSpace(' ') - TYPE_REFERENCE - FUNCTION_TYPE - FUNCTION_TYPE_RECEIVER - TYPE_REFERENCE - DEFINITELY_NOT_NULL_TYPE - USER_TYPE - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('T') - PsiElement(EXCLEXCL)('!!') - PsiElement(DOT)('.') - VALUE_PARAMETER_LIST - PsiElement(LPAR)('(') - VALUE_PARAMETER - TYPE_REFERENCE - DEFINITELY_NOT_NULL_TYPE - USER_TYPE - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('T') - PsiElement(EXCLEXCL)('!!') - PsiElement(RPAR)(')') - PsiWhiteSpace(' ') - PsiElement(ARROW)('->') - PsiWhiteSpace(' ') - TYPE_REFERENCE - DEFINITELY_NOT_NULL_TYPE - USER_TYPE - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('T') - PsiElement(EXCLEXCL)('!!') - PsiElement(RPAR)(')') - PsiElement(COLON)(':') - PsiWhiteSpace(' ') - TYPE_REFERENCE - DEFINITELY_NOT_NULL_TYPE - USER_TYPE - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('T') + PsiElement(IDENTIFIER)('T') + PsiErrorElement:Expecting comma or ')' + + PsiErrorElement:Expecting ')' PsiElement(EXCLEXCL)('!!') - PsiWhiteSpace(' ') + PsiErrorElement:Expecting a top level declaration + PsiElement(COMMA)(',') + PsiWhiteSpace(' ') + PsiErrorElement:Expecting a top level declaration + PsiElement(IDENTIFIER)('y') + PsiErrorElement:Expecting a top level declaration + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + PsiErrorElement:Expecting a top level declaration + PsiElement(IDENTIFIER)('List') + PsiErrorElement:Expecting a top level declaration + PsiElement(LT)('<') + PsiErrorElement:Expecting a top level declaration + PsiElement(IDENTIFIER)('T') + PsiErrorElement:Expecting a top level declaration + PsiElement(EXCLEXCL)('!!') + PsiErrorElement:Expecting a top level declaration + PsiElement(GT)('>') + PsiErrorElement:Expecting a top level declaration + PsiElement(COMMA)(',') + PsiWhiteSpace(' ') + PsiErrorElement:Expecting a top level declaration + PsiElement(IDENTIFIER)('z') + PsiErrorElement:Expecting a top level declaration + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + PsiErrorElement:Expecting a top level declaration + PsiElement(IDENTIFIER)('T') + PsiErrorElement:Expecting a top level declaration + PsiElement(EXCLEXCL)('!!') + PsiErrorElement:Expecting a top level declaration + PsiElement(DOT)('.') + PsiErrorElement:Expecting a top level declaration + PsiElement(LPAR)('(') + PsiErrorElement:Expecting a top level declaration + PsiElement(IDENTIFIER)('T') + PsiErrorElement:Expecting a top level declaration + PsiElement(EXCLEXCL)('!!') + PsiErrorElement:Expecting a top level declaration + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + PsiErrorElement:Expecting a top level declaration + PsiElement(ARROW)('->') + PsiWhiteSpace(' ') + PsiErrorElement:Expecting a top level declaration + PsiElement(IDENTIFIER)('T') + PsiErrorElement:Expecting a top level declaration + PsiElement(EXCLEXCL)('!!') + PsiErrorElement:Expecting a top level declaration + PsiElement(RPAR)(')') + PsiErrorElement:Expecting a top level declaration + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + PsiErrorElement:Expecting a top level declaration + PsiElement(IDENTIFIER)('T') + PsiErrorElement:Expecting a top level declaration + PsiElement(EXCLEXCL)('!!') + PsiWhiteSpace(' ') + FUN + PsiErrorElement:Expecting a top level declaration + BLOCK PsiElement(LBRACE)('{') PsiElement(RBRACE)('}') @@ -112,99 +110,95 @@ KtFile: DefinitelyNotNullType.kt PsiElement(IDENTIFIER)('x') PsiElement(COLON)(':') PsiWhiteSpace(' ') - TYPE_REFERENCE - NULLABLE_TYPE - DEFINITELY_NOT_NULL_TYPE - USER_TYPE - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('T') - PsiElement(EXCLEXCL)('!!') - PsiElement(QUEST)('?') - PsiElement(COMMA)(',') - PsiWhiteSpace(' ') - VALUE_PARAMETER - PsiElement(IDENTIFIER)('y') - PsiElement(COLON)(':') - PsiWhiteSpace(' ') TYPE_REFERENCE USER_TYPE REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('List') - TYPE_ARGUMENT_LIST - PsiElement(LT)('<') - TYPE_PROJECTION - TYPE_REFERENCE - NULLABLE_TYPE - DEFINITELY_NOT_NULL_TYPE - USER_TYPE - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('T') - PsiElement(EXCLEXCL)('!!') - PsiElement(QUEST)('?') - PsiElement(GT)('>') - PsiElement(COMMA)(',') - PsiWhiteSpace(' ') - VALUE_PARAMETER - PsiElement(IDENTIFIER)('z') - PsiElement(COLON)(':') - PsiWhiteSpace(' ') - TYPE_REFERENCE - FUNCTION_TYPE - FUNCTION_TYPE_RECEIVER - TYPE_REFERENCE - NULLABLE_TYPE - DEFINITELY_NOT_NULL_TYPE - USER_TYPE - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('T') - PsiElement(EXCLEXCL)('!!') - PsiElement(QUEST)('?') - PsiElement(DOT)('.') - VALUE_PARAMETER_LIST - PsiElement(LPAR)('(') - VALUE_PARAMETER - TYPE_REFERENCE - NULLABLE_TYPE - DEFINITELY_NOT_NULL_TYPE - USER_TYPE - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('T') - PsiElement(EXCLEXCL)('!!') - PsiElement(QUEST)('?') - PsiElement(RPAR)(')') - PsiWhiteSpace(' ') - PsiElement(ARROW)('->') - PsiWhiteSpace(' ') - TYPE_REFERENCE - NULLABLE_TYPE - DEFINITELY_NOT_NULL_TYPE - USER_TYPE - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('T') - PsiElement(EXCLEXCL)('!!') - PsiElement(QUEST)('?') - PsiElement(COMMA)(',') - PsiWhiteSpace(' ') - VALUE_PARAMETER - PsiElement(IDENTIFIER)('w') - PsiElement(COLON)(':') - PsiWhiteSpace(' ') - TYPE_REFERENCE - DEFINITELY_NOT_NULL_TYPE - USER_TYPE - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('String') - PsiElement(EXCLEXCL)('!!') - PsiElement(RPAR)(')') - PsiElement(COLON)(':') - PsiWhiteSpace(' ') - TYPE_REFERENCE - DEFINITELY_NOT_NULL_TYPE - USER_TYPE - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('T') + PsiElement(IDENTIFIER)('T') + PsiErrorElement:Expecting comma or ')' + + PsiErrorElement:Expecting ')' PsiElement(EXCLEXCL)('!!') - PsiWhiteSpace(' ') + PsiErrorElement:Expecting a top level declaration + PsiElement(QUEST)('?') + PsiErrorElement:Expecting a top level declaration + PsiElement(COMMA)(',') + PsiWhiteSpace(' ') + PsiErrorElement:Expecting a top level declaration + PsiElement(IDENTIFIER)('y') + PsiErrorElement:Expecting a top level declaration + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + PsiErrorElement:Expecting a top level declaration + PsiElement(IDENTIFIER)('List') + PsiErrorElement:Expecting a top level declaration + PsiElement(LT)('<') + PsiErrorElement:Expecting a top level declaration + PsiElement(IDENTIFIER)('T') + PsiErrorElement:Expecting a top level declaration + PsiElement(EXCLEXCL)('!!') + PsiErrorElement:Expecting a top level declaration + PsiElement(QUEST)('?') + PsiErrorElement:Expecting a top level declaration + PsiElement(GT)('>') + PsiErrorElement:Expecting a top level declaration + PsiElement(COMMA)(',') + PsiWhiteSpace(' ') + PsiErrorElement:Expecting a top level declaration + PsiElement(IDENTIFIER)('z') + PsiErrorElement:Expecting a top level declaration + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + PsiErrorElement:Expecting a top level declaration + PsiElement(IDENTIFIER)('T') + PsiErrorElement:Expecting a top level declaration + PsiElement(EXCLEXCL)('!!') + PsiErrorElement:Expecting a top level declaration + PsiElement(SAFE_ACCESS)('?.') + PsiErrorElement:Expecting a top level declaration + PsiElement(LPAR)('(') + PsiErrorElement:Expecting a top level declaration + PsiElement(IDENTIFIER)('T') + PsiErrorElement:Expecting a top level declaration + PsiElement(EXCLEXCL)('!!') + PsiErrorElement:Expecting a top level declaration + PsiElement(QUEST)('?') + PsiErrorElement:Expecting a top level declaration + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + PsiErrorElement:Expecting a top level declaration + PsiElement(ARROW)('->') + PsiWhiteSpace(' ') + PsiErrorElement:Expecting a top level declaration + PsiElement(IDENTIFIER)('T') + PsiErrorElement:Expecting a top level declaration + PsiElement(EXCLEXCL)('!!') + PsiErrorElement:Expecting a top level declaration + PsiElement(QUEST)('?') + PsiErrorElement:Expecting a top level declaration + PsiElement(COMMA)(',') + PsiWhiteSpace(' ') + PsiErrorElement:Expecting a top level declaration + PsiElement(IDENTIFIER)('w') + PsiErrorElement:Expecting a top level declaration + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + PsiErrorElement:Expecting a top level declaration + PsiElement(IDENTIFIER)('String') + PsiErrorElement:Expecting a top level declaration + PsiElement(EXCLEXCL)('!!') + PsiErrorElement:Expecting a top level declaration + PsiElement(RPAR)(')') + PsiErrorElement:Expecting a top level declaration + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + PsiErrorElement:Expecting a top level declaration + PsiElement(IDENTIFIER)('T') + PsiErrorElement:Expecting a top level declaration + PsiElement(EXCLEXCL)('!!') + PsiWhiteSpace(' ') + FUN + PsiErrorElement:Expecting a top level declaration + BLOCK PsiElement(LBRACE)('{') PsiElement(RBRACE)('}') diff --git a/compiler/testData/psi/SimpleIntersections.kt b/compiler/testData/psi/SimpleIntersections.kt new file mode 100644 index 00000000000..7b842d21450 --- /dev/null +++ b/compiler/testData/psi/SimpleIntersections.kt @@ -0,0 +1,11 @@ +fun foo1(x: T & Any) {} +fun foo2(x: List) {} +fun foo3(x: List) {} +fun foo4(x: (T & Any)) {} +fun foo5(x: T? & Any?) {} +fun foo6(x: T & Any & Any) {} +fun foo7(x: T & (Any & Any)) {} +fun T & Any.foo8() {} +fun (T & Any).foo9() {} +fun foo10(x: T & Any.() -> Unit) {} +fun foo11(x: (T & Any).() -> Unit) {} diff --git a/compiler/testData/psi/SimpleIntersections.txt b/compiler/testData/psi/SimpleIntersections.txt new file mode 100644 index 00000000000..72c1be6ac90 --- /dev/null +++ b/compiler/testData/psi/SimpleIntersections.txt @@ -0,0 +1,462 @@ +KtFile: SimpleIntersections.kt + PACKAGE_DIRECTIVE + + IMPORT_LIST + + FUN + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + TYPE_PARAMETER_LIST + PsiElement(LT)('<') + TYPE_PARAMETER + PsiElement(IDENTIFIER)('T') + PsiElement(GT)('>') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo1') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + VALUE_PARAMETER + PsiElement(IDENTIFIER)('x') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + INTERSECTION_TYPE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('T') + PsiWhiteSpace(' ') + PsiElement(AND)('&') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Any') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n') + FUN + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + TYPE_PARAMETER_LIST + PsiElement(LT)('<') + TYPE_PARAMETER + PsiElement(IDENTIFIER)('T') + PsiElement(GT)('>') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo2') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + VALUE_PARAMETER + PsiElement(IDENTIFIER)('x') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('List') + TYPE_ARGUMENT_LIST + PsiElement(LT)('<') + TYPE_PROJECTION + TYPE_REFERENCE + INTERSECTION_TYPE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('T') + PsiWhiteSpace(' ') + PsiElement(AND)('&') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Any') + PsiElement(GT)('>') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n') + FUN + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + TYPE_PARAMETER_LIST + PsiElement(LT)('<') + TYPE_PARAMETER + PsiElement(IDENTIFIER)('T') + PsiElement(GT)('>') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo3') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + VALUE_PARAMETER + PsiElement(IDENTIFIER)('x') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('List') + TYPE_ARGUMENT_LIST + PsiElement(LT)('<') + TYPE_PROJECTION + MODIFIER_LIST + PsiElement(out)('out') + PsiWhiteSpace(' ') + TYPE_REFERENCE + INTERSECTION_TYPE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('T') + PsiWhiteSpace(' ') + PsiElement(AND)('&') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Any') + PsiElement(GT)('>') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n') + FUN + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + TYPE_PARAMETER_LIST + PsiElement(LT)('<') + TYPE_PARAMETER + PsiElement(IDENTIFIER)('T') + PsiElement(GT)('>') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo4') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + VALUE_PARAMETER + PsiElement(IDENTIFIER)('x') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + PsiElement(LPAR)('(') + INTERSECTION_TYPE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('T') + PsiWhiteSpace(' ') + PsiElement(AND)('&') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Any') + PsiElement(RPAR)(')') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n') + FUN + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + TYPE_PARAMETER_LIST + PsiElement(LT)('<') + TYPE_PARAMETER + PsiElement(IDENTIFIER)('T') + PsiElement(GT)('>') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo5') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + VALUE_PARAMETER + PsiElement(IDENTIFIER)('x') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + INTERSECTION_TYPE + TYPE_REFERENCE + NULLABLE_TYPE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('T') + PsiElement(QUEST)('?') + PsiWhiteSpace(' ') + PsiElement(AND)('&') + PsiWhiteSpace(' ') + TYPE_REFERENCE + NULLABLE_TYPE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Any') + PsiElement(QUEST)('?') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n') + FUN + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + TYPE_PARAMETER_LIST + PsiElement(LT)('<') + TYPE_PARAMETER + PsiElement(IDENTIFIER)('T') + PsiElement(GT)('>') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo6') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + VALUE_PARAMETER + PsiElement(IDENTIFIER)('x') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + INTERSECTION_TYPE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('T') + PsiWhiteSpace(' ') + PsiElement(AND)('&') + PsiWhiteSpace(' ') + TYPE_REFERENCE + INTERSECTION_TYPE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Any') + PsiWhiteSpace(' ') + PsiElement(AND)('&') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Any') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n') + FUN + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + TYPE_PARAMETER_LIST + PsiElement(LT)('<') + TYPE_PARAMETER + PsiElement(IDENTIFIER)('T') + PsiElement(GT)('>') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo7') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + VALUE_PARAMETER + PsiElement(IDENTIFIER)('x') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + INTERSECTION_TYPE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('T') + PsiWhiteSpace(' ') + PsiElement(AND)('&') + PsiWhiteSpace(' ') + TYPE_REFERENCE + PsiElement(LPAR)('(') + INTERSECTION_TYPE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Any') + PsiWhiteSpace(' ') + PsiElement(AND)('&') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Any') + PsiElement(RPAR)(')') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n') + FUN + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + TYPE_PARAMETER_LIST + PsiElement(LT)('<') + TYPE_PARAMETER + PsiElement(IDENTIFIER)('T') + PsiElement(GT)('>') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('T') + PsiErrorElement:Expecting '(' + + PsiWhiteSpace(' ') + PsiErrorElement:Expecting a top level declaration + PsiElement(AND)('&') + PsiWhiteSpace(' ') + PsiErrorElement:Expecting a top level declaration + PsiElement(IDENTIFIER)('Any') + PsiErrorElement:Expecting a top level declaration + PsiElement(DOT)('.') + PsiErrorElement:Expecting a top level declaration + PsiElement(IDENTIFIER)('foo8') + PsiErrorElement:Expecting a top level declaration + PsiElement(LPAR)('(') + PsiErrorElement:Expecting a top level declaration + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + FUN + PsiErrorElement:Expecting a top level declaration + + BLOCK + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n') + FUN + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + TYPE_PARAMETER_LIST + PsiElement(LT)('<') + TYPE_PARAMETER + PsiElement(IDENTIFIER)('T') + PsiElement(GT)('>') + PsiWhiteSpace(' ') + TYPE_REFERENCE + PsiElement(LPAR)('(') + INTERSECTION_TYPE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('T') + PsiWhiteSpace(' ') + PsiElement(AND)('&') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Any') + PsiElement(RPAR)(')') + PsiElement(DOT)('.') + PsiElement(IDENTIFIER)('foo9') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n') + FUN + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + TYPE_PARAMETER_LIST + PsiElement(LT)('<') + TYPE_PARAMETER + PsiElement(IDENTIFIER)('T') + PsiElement(GT)('>') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo10') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + VALUE_PARAMETER + PsiElement(IDENTIFIER)('x') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + INTERSECTION_TYPE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('T') + PsiWhiteSpace(' ') + PsiElement(AND)('&') + PsiWhiteSpace(' ') + TYPE_REFERENCE + FUNCTION_TYPE + FUNCTION_TYPE_RECEIVER + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Any') + PsiElement(DOT)('.') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + PsiElement(ARROW)('->') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Unit') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n') + FUN + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + TYPE_PARAMETER_LIST + PsiElement(LT)('<') + TYPE_PARAMETER + PsiElement(IDENTIFIER)('T') + PsiElement(GT)('>') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo11') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + VALUE_PARAMETER + PsiElement(IDENTIFIER)('x') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + FUNCTION_TYPE + FUNCTION_TYPE_RECEIVER + TYPE_REFERENCE + PsiElement(LPAR)('(') + INTERSECTION_TYPE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('T') + PsiWhiteSpace(' ') + PsiElement(AND)('&') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Any') + PsiElement(RPAR)(')') + PsiElement(DOT)('.') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + PsiElement(ARROW)('->') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Unit') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') \ No newline at end of file diff --git a/compiler/testData/versionRequirement/definitelyNotNull.kt b/compiler/testData/versionRequirement/definitelyNotNull.kt index 3e98085369c..b8725570ca4 100644 --- a/compiler/testData/versionRequirement/definitelyNotNull.kt +++ b/compiler/testData/versionRequirement/definitelyNotNull.kt @@ -1,33 +1,33 @@ package test interface A { - fun foo(x: T!!) + fun foo(x: T & Any) - val w: T!! + val w: T & Any } -class B(r: X!!) +class B(r: X & Any) fun inside() { object : A { - override fun foo(x: K!!) { + override fun foo(x: K & Any) { } - override val w: K!! + override val w: K & Any get() = TODO("") } } -fun bar1(x: F!!) {} +fun bar1(x: F & Any) {} fun bar2(x: F) = x!! -val E.nn: E!! get() = this!! +val E.nn: E & Any get() = this!! class Outer { - abstract class R1 : A - abstract class R2 : A + abstract class R1 : A + abstract class R2 : A abstract class W : A } -typealias Alias = A +typealias Alias = A diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java index a383ddb864f..2e799d2d16e 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java @@ -10122,6 +10122,76 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { } } + @Nested + @TestMetadata("compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection") + @TestDataPath("$PROJECT_ROOT") + public class ExplicitDefinitelyNotNullableViaIntersection { + @Test + public void testAllFilesPresentInExplicitDefinitelyNotNullableViaIntersection() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @Test + @TestMetadata("approximation.kt") + public void testApproximation() throws Exception { + runTest("compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/approximation.kt"); + } + + @Test + @TestMetadata("bareTypes.kt") + public void testBareTypes() throws Exception { + runTest("compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/bareTypes.kt"); + } + + @Test + @TestMetadata("disabledFeature.kt") + public void testDisabledFeature() throws Exception { + runTest("compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/disabledFeature.kt"); + } + + @Test + @TestMetadata("inference.kt") + public void testInference() throws Exception { + runTest("compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/inference.kt"); + } + + @Test + @TestMetadata("isAsOperators.kt") + public void testIsAsOperators() throws Exception { + runTest("compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/isAsOperators.kt"); + } + + @Test + @TestMetadata("isAsOperatorsEnabled.kt") + public void testIsAsOperatorsEnabled() throws Exception { + runTest("compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/isAsOperatorsEnabled.kt"); + } + + @Test + @TestMetadata("notApplicable.kt") + public void testNotApplicable() throws Exception { + runTest("compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/notApplicable.kt"); + } + + @Test + @TestMetadata("overrides.kt") + public void testOverrides() throws Exception { + runTest("compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/overrides.kt"); + } + + @Test + @TestMetadata("overridesJavaAnnotated.kt") + public void testOverridesJavaAnnotated() throws Exception { + runTest("compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/overridesJavaAnnotated.kt"); + } + + @Test + @TestMetadata("simple.kt") + public void testSimple() throws Exception { + runTest("compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/simple.kt"); + } + } + @Nested @TestMetadata("compiler/testData/diagnostics/tests/exposed") @TestDataPath("$PROJECT_ROOT") diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/test/testFramework/KtUsefulTestCase.java b/compiler/tests-common/tests/org/jetbrains/kotlin/test/testFramework/KtUsefulTestCase.java index 37f1c2847de..a98b1c91118 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/test/testFramework/KtUsefulTestCase.java +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/test/testFramework/KtUsefulTestCase.java @@ -799,6 +799,12 @@ public abstract class KtUsefulTestCase extends TestCase { fileText = FileUtil.loadFile(new File(filePath), StandardCharsets.UTF_8); } catch (FileNotFoundException e) { + try { + FileUtil.writeToFile(new File(filePath), actualText); + } + catch (IOException exception) { + throw new AssertionError(exception); + } throw new AssertionFailedError("No output text found. File " + filePath + " created."); } catch (IOException e) { diff --git a/compiler/tests-gen/org/jetbrains/kotlin/parsing/ParsingTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/parsing/ParsingTestGenerated.java index 5010f30c5f6..32aa635f7f3 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/parsing/ParsingTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/parsing/ParsingTestGenerated.java @@ -36,6 +36,11 @@ public class ParsingTestGenerated extends AbstractParsingTest { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/psi"), Pattern.compile("^(.*)\\.kts?$"), null, true); } + @TestMetadata("AnnotatedIntersections.kt") + public void testAnnotatedIntersections() throws Exception { + runTest("compiler/testData/psi/AnnotatedIntersections.kt"); + } + @TestMetadata("AnonymousInitializer.kt") public void testAnonymousInitializer() throws Exception { runTest("compiler/testData/psi/AnonymousInitializer.kt"); @@ -626,6 +631,11 @@ public class ParsingTestGenerated extends AbstractParsingTest { runTest("compiler/testData/psi/SimpleExpressions.kt"); } + @TestMetadata("SimpleIntersections.kt") + public void testSimpleIntersections() throws Exception { + runTest("compiler/testData/psi/SimpleIntersections.kt"); + } + @TestMetadata("SimpleModifiers.kt") public void testSimpleModifiers() throws Exception { runTest("compiler/testData/psi/SimpleModifiers.kt"); diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.kt b/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.kt index 3e873c24270..b1ae714a78b 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.kt @@ -24,11 +24,13 @@ import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.calls.inference.isCaptured import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns import org.jetbrains.kotlin.types.* -import org.jetbrains.kotlin.types.checker.* +import org.jetbrains.kotlin.types.checker.KotlinTypeChecker +import org.jetbrains.kotlin.types.checker.NewCapturedType +import org.jetbrains.kotlin.types.checker.NewCapturedTypeConstructor +import org.jetbrains.kotlin.types.checker.intersectTypes import org.jetbrains.kotlin.types.model.TypeArgumentMarker import org.jetbrains.kotlin.types.model.TypeVariableTypeConstructorMarker import org.jetbrains.kotlin.utils.addToStdlib.safeAs -import java.util.* enum class TypeNullability { NOT_NULL, @@ -58,6 +60,7 @@ fun KotlinType.isNullableNothing(): Boolean = KotlinBuiltIns.isNullableNothing(t fun KotlinType.isNothingOrNullableNothing(): Boolean = KotlinBuiltIns.isNothingOrNullableNothing(this) fun KotlinType.isUnit(): Boolean = KotlinBuiltIns.isUnit(this) fun KotlinType.isAnyOrNullableAny(): Boolean = KotlinBuiltIns.isAnyOrNullableAny(this) +fun KotlinType.isAny(): Boolean = KotlinBuiltIns.isAny(this) fun KotlinType.isNullableAny(): Boolean = KotlinBuiltIns.isNullableAny(this) fun KotlinType.isBoolean(): Boolean = KotlinBuiltIns.isBoolean(this) fun KotlinType.isPrimitiveNumberType(): Boolean = KotlinBuiltIns.isPrimitiveType(this) && !isBoolean() diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java b/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java index a4e61deb03c..177f7b38364 100644 --- a/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java @@ -10116,6 +10116,76 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag } } + @Nested + @TestMetadata("compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection") + @TestDataPath("$PROJECT_ROOT") + public class ExplicitDefinitelyNotNullableViaIntersection { + @Test + public void testAllFilesPresentInExplicitDefinitelyNotNullableViaIntersection() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @Test + @TestMetadata("approximation.kt") + public void testApproximation() throws Exception { + runTest("compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/approximation.kt"); + } + + @Test + @TestMetadata("bareTypes.kt") + public void testBareTypes() throws Exception { + runTest("compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/bareTypes.kt"); + } + + @Test + @TestMetadata("disabledFeature.kt") + public void testDisabledFeature() throws Exception { + runTest("compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/disabledFeature.kt"); + } + + @Test + @TestMetadata("inference.kt") + public void testInference() throws Exception { + runTest("compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/inference.kt"); + } + + @Test + @TestMetadata("isAsOperators.kt") + public void testIsAsOperators() throws Exception { + runTest("compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/isAsOperators.kt"); + } + + @Test + @TestMetadata("isAsOperatorsEnabled.kt") + public void testIsAsOperatorsEnabled() throws Exception { + runTest("compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/isAsOperatorsEnabled.kt"); + } + + @Test + @TestMetadata("notApplicable.kt") + public void testNotApplicable() throws Exception { + runTest("compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/notApplicable.kt"); + } + + @Test + @TestMetadata("overrides.kt") + public void testOverrides() throws Exception { + runTest("compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/overrides.kt"); + } + + @Test + @TestMetadata("overridesJavaAnnotated.kt") + public void testOverridesJavaAnnotated() throws Exception { + runTest("compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/overridesJavaAnnotated.kt"); + } + + @Test + @TestMetadata("simple.kt") + public void testSimple() throws Exception { + runTest("compiler/testData/diagnostics/tests/explicitDefinitelyNotNullableViaIntersection/simple.kt"); + } + } + @Nested @TestMetadata("compiler/testData/diagnostics/tests/exposed") @TestDataPath("$PROJECT_ROOT")