From 5779ac15c0d498eaef24bbfee92a317f1e076c66 Mon Sep 17 00:00:00 2001 From: Svetlana Isakova Date: Wed, 22 Aug 2012 12:34:57 +0400 Subject: [PATCH] Not get supertypes of Nothing (exception EA-37833) --- .../calls/inference/ConstraintSystemImpl.java | 3 +++ .../tests/incompleteCode/checkNothingIsSubtype.kt | 14 ++++++++++++++ .../jet/checkers/JetDiagnosticsTestGenerated.java | 5 +++++ 3 files changed, 22 insertions(+) create mode 100644 compiler/testData/diagnostics/tests/incompleteCode/checkNothingIsSubtype.kt diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintSystemImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintSystemImpl.java index 4a55b396da9..2072152fa58 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintSystemImpl.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintSystemImpl.java @@ -27,6 +27,7 @@ import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor; import org.jetbrains.jet.lang.types.*; import org.jetbrains.jet.lang.types.checker.TypeCheckingProcedure; import org.jetbrains.jet.lang.resolve.calls.inference.TypeConstraintsImpl.ConstraintKind; +import org.jetbrains.jet.lang.types.lang.JetStandardClasses; import java.util.*; @@ -190,6 +191,7 @@ public class ConstraintSystemImpl implements ConstraintSystem { } switch (constraintKind) { case SUPER_TYPE: { + if (JetStandardClasses.isNothingOrNullableNothing(constrainingType)) break; JetType correspondingSupertype = TypeCheckingProcedure.findCorrespondingSupertype(constrainingType, subjectType); if (correspondingSupertype != null) { constrainingType = correspondingSupertype; @@ -197,6 +199,7 @@ public class ConstraintSystemImpl implements ConstraintSystem { break; } case SUB_TYPE: { + if (JetStandardClasses.isNothingOrNullableNothing(subjectType)) break; JetType correspondingSupertype = TypeCheckingProcedure.findCorrespondingSupertype(subjectType, constrainingType); if (correspondingSupertype != null) { subjectType = correspondingSupertype; diff --git a/compiler/testData/diagnostics/tests/incompleteCode/checkNothingIsSubtype.kt b/compiler/testData/diagnostics/tests/incompleteCode/checkNothingIsSubtype.kt new file mode 100644 index 00000000000..0aa8318a92d --- /dev/null +++ b/compiler/testData/diagnostics/tests/incompleteCode/checkNothingIsSubtype.kt @@ -0,0 +1,14 @@ +package d + +trait A + +fun infer(a: A) : T {} + +fun test(nothing: Nothing?) { + val i = infer(nothing) +} + +fun sum(a : IntArray) : Int { + for (n + return "?" +} diff --git a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java index f2c1998a844..127378e4429 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java @@ -1304,6 +1304,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage doTest("compiler/testData/diagnostics/tests/incompleteCode/arrayBracketsRange.kt"); } + @TestMetadata("checkNothingIsSubtype.kt") + public void testCheckNothingIsSubtype() throws Exception { + doTest("compiler/testData/diagnostics/tests/incompleteCode/checkNothingIsSubtype.kt"); + } + @TestMetadata("incompleteAssignment.kt") public void testIncompleteAssignment() throws Exception { doTest("compiler/testData/diagnostics/tests/incompleteCode/incompleteAssignment.kt");