diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java index a28568d8ce8..6821cd5e0c2 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java @@ -18,6 +18,9 @@ import static org.jetbrains.jet.lang.diagnostics.Severity.WARNING; public interface Errors { UnresolvedReferenceDiagnosticFactory UNRESOLVED_REFERENCE = UnresolvedReferenceDiagnosticFactory.INSTANCE; + RedeclarationDiagnosticFactory REDECLARATION = RedeclarationDiagnosticFactory.INSTANCE; + PsiElementOnlyDiagnosticFactory2 TYPE_MISMATCH = PsiElementOnlyDiagnosticFactory2.create(ERROR, "Type mismatch: inferred type is {1} but {0} was expected"); + SimpleDiagnosticFactory SAFE_CALLS_ARE_NOT_ALLOWED_ON_NAMESPACES = SimpleDiagnosticFactory.create(ERROR, "Safe calls are not allowed on namespaces"); SimpleDiagnosticFactory TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM = SimpleDiagnosticFactory.create(ERROR, "Type checking has run into a recursive problem"); // TODO: message SimpleDiagnosticFactory RETURN_NOT_ALLOWED = SimpleDiagnosticFactory.create(ERROR, "'return' is not allowed here"); @@ -199,7 +202,6 @@ public interface Errors { ParameterizedDiagnosticFactory1 TYPE_MISMATCH_IN_CONDITION = ParameterizedDiagnosticFactory1.create(ERROR, "Condition must be of type Boolean, but was of type {0}"); ParameterizedDiagnosticFactory2 TYPE_MISMATCH_IN_TUPLE_PATTERN = ParameterizedDiagnosticFactory2.create(ERROR, "Type mismatch: subject is of type {0} but the pattern is of type Tuple{1}"); // TODO: message ParameterizedDiagnosticFactory2 TYPE_MISMATCH_IN_BINDING_PATTERN = ParameterizedDiagnosticFactory2.create(ERROR, "{0} must be a supertype of {1}. Use 'is' to match against {0}"); - ParameterizedDiagnosticFactory2 TYPE_MISMATCH = ParameterizedDiagnosticFactory2.create(ERROR, "Type mismatch: inferred type is {1} but {0} was expected"); ParameterizedDiagnosticFactory2 INCOMPATIBLE_TYPES = ParameterizedDiagnosticFactory2.create(ERROR, "Incompatible types: {0} and {1}"); ParameterizedDiagnosticFactory3> INCONSISTENT_TYPE_PARAMETER_VALUES = new ParameterizedDiagnosticFactory3>(ERROR, "Type parameter {0} of {1} has inconsistent values: {2}") { @@ -280,6 +282,5 @@ public interface Errors { }; - RedeclarationDiagnosticFactory REDECLARATION = RedeclarationDiagnosticFactory.INSTANCE; } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/ParameterizedDiagnosticFactory2.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/ParameterizedDiagnosticFactory2.java index 81540baca6b..d62a90d6a49 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/ParameterizedDiagnosticFactory2.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/ParameterizedDiagnosticFactory2.java @@ -2,13 +2,12 @@ package org.jetbrains.jet.lang.diagnostics; import com.intellij.lang.ASTNode; import com.intellij.openapi.util.TextRange; -import com.intellij.psi.PsiElement; import org.jetbrains.annotations.NotNull; /** * @author abreslav */ -public class ParameterizedDiagnosticFactory2 extends AbstractDiagnosticFactory { +public class ParameterizedDiagnosticFactory2 extends PsiElementOnlyDiagnosticFactory2 { public static ParameterizedDiagnosticFactory2 create(Severity severity, String messageStub) { return new ParameterizedDiagnosticFactory2(severity, messageStub); } @@ -17,18 +16,6 @@ public class ParameterizedDiagnosticFactory2 extends AbstractDiagnosticFac super(severity, messageStub); } - protected String makeMessage(@NotNull A a, @NotNull B b) { - return messageFormat.format(new Object[] {makeMessageForA(a), makeMessageForB(b)}); - } - - protected String makeMessageForA(@NotNull A a) { - return a.toString(); - } - - protected String makeMessageForB(@NotNull B b) { - return b.toString(); - } - @NotNull public Diagnostic on(@NotNull TextRange range, @NotNull A a, @NotNull B b) { return new GenericDiagnostic(this, severity, makeMessage(a, b), range); @@ -39,8 +26,4 @@ public class ParameterizedDiagnosticFactory2 extends AbstractDiagnosticFac return on(node.getTextRange(), a, b); } - @NotNull - public Diagnostic on(@NotNull PsiElement element, @NotNull A a, @NotNull B b) { - return new DiagnosticWithPsiElement(this, severity, makeMessage(a, b), element); - } } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/PsiElementOnlyDiagnosticFactory2.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/PsiElementOnlyDiagnosticFactory2.java new file mode 100644 index 00000000000..2e1cd9e90c5 --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/PsiElementOnlyDiagnosticFactory2.java @@ -0,0 +1,35 @@ +package org.jetbrains.jet.lang.diagnostics; + +import com.intellij.psi.PsiElement; +import org.jetbrains.annotations.NotNull; + +/** + * @author abreslav + */ +public class PsiElementOnlyDiagnosticFactory2 extends AbstractDiagnosticFactory { + + public static PsiElementOnlyDiagnosticFactory2 create(Severity severity, String message) { + return new PsiElementOnlyDiagnosticFactory2(severity, message); + } + + public PsiElementOnlyDiagnosticFactory2(Severity severity, String message) { + super(severity, message); + } + + protected String makeMessage(@NotNull A a, @NotNull B b) { + return messageFormat.format(new Object[] {makeMessageForA(a), makeMessageForB(b)}); + } + + protected String makeMessageForA(@NotNull A a) { + return a.toString(); + } + + protected String makeMessageForB(@NotNull B b) { + return b.toString(); + } + + @NotNull + public Diagnostic on(@NotNull PsiElement element, @NotNull A a, @NotNull B b) { + return new DiagnosticWithPsiElement(this, severity, makeMessage(a, b), element); + } +} diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/JetTypeInferrer.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/JetTypeInferrer.java index 667bd9c0b07..6950b92af0f 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/JetTypeInferrer.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/JetTypeInferrer.java @@ -16,6 +16,7 @@ import org.jetbrains.jet.lang.cfg.JetFlowInformationProvider; import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; import org.jetbrains.jet.lang.diagnostics.Diagnostic; +import org.jetbrains.jet.lang.diagnostics.DiagnosticWithPsiElement; import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.resolve.*; import org.jetbrains.jet.lang.resolve.calls.CallResolver; @@ -471,9 +472,10 @@ public class JetTypeInferrer { @Override public void report(@NotNull Diagnostic diagnostic) { - if (diagnostic.getFactory() == TYPE_MISMATCH) { + if (diagnostic.getFactory() == TYPE_MISMATCH && ((DiagnosticWithPsiElement) diagnostic).getPsiElement() == expressionToWatch) { mismatchFound[0] = true; } + super.report(diagnostic); } }; } diff --git a/idea/testData/checker/regression/CoercionToUnit.jet b/idea/testData/checker/regression/CoercionToUnit.jet new file mode 100644 index 00000000000..5d814eadc9e --- /dev/null +++ b/idea/testData/checker/regression/CoercionToUnit.jet @@ -0,0 +1,9 @@ +fun foo(u : Unit) : Int = 1 + +fun test() : Int { + foo(1) + val a : fun() : Unit = { + foo(1) + } + return 1 +} \ No newline at end of file