Coercion to Unit fixed
This commit is contained in:
@@ -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<JetType, JetType> 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<JetType> TYPE_MISMATCH_IN_CONDITION = ParameterizedDiagnosticFactory1.create(ERROR, "Condition must be of type Boolean, but was of type {0}");
|
||||
ParameterizedDiagnosticFactory2<JetType, Integer> 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<JetType, JetType> TYPE_MISMATCH_IN_BINDING_PATTERN = ParameterizedDiagnosticFactory2.create(ERROR, "{0} must be a supertype of {1}. Use 'is' to match against {0}");
|
||||
ParameterizedDiagnosticFactory2<JetType, JetType> TYPE_MISMATCH = ParameterizedDiagnosticFactory2.create(ERROR, "Type mismatch: inferred type is {1} but {0} was expected");
|
||||
ParameterizedDiagnosticFactory2<JetType, JetType> INCOMPATIBLE_TYPES = ParameterizedDiagnosticFactory2.create(ERROR, "Incompatible types: {0} and {1}");
|
||||
|
||||
ParameterizedDiagnosticFactory3<TypeParameterDescriptor, ClassDescriptor, Collection<JetType>> INCONSISTENT_TYPE_PARAMETER_VALUES = new ParameterizedDiagnosticFactory3<TypeParameterDescriptor, ClassDescriptor, Collection<JetType>>(ERROR, "Type parameter {0} of {1} has inconsistent values: {2}") {
|
||||
@@ -280,6 +282,5 @@ public interface Errors {
|
||||
};
|
||||
|
||||
|
||||
RedeclarationDiagnosticFactory REDECLARATION = RedeclarationDiagnosticFactory.INSTANCE;
|
||||
|
||||
}
|
||||
|
||||
+1
-18
@@ -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<A, B> extends AbstractDiagnosticFactory {
|
||||
public class ParameterizedDiagnosticFactory2<A, B> extends PsiElementOnlyDiagnosticFactory2<A,B> {
|
||||
public static <A, B> ParameterizedDiagnosticFactory2<A, B> create(Severity severity, String messageStub) {
|
||||
return new ParameterizedDiagnosticFactory2<A, B>(severity, messageStub);
|
||||
}
|
||||
@@ -17,18 +16,6 @@ public class ParameterizedDiagnosticFactory2<A, B> 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<A, B> extends AbstractDiagnosticFac
|
||||
return on(node.getTextRange(), a, b);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Diagnostic on(@NotNull PsiElement element, @NotNull A a, @NotNull B b) {
|
||||
return new DiagnosticWithPsiElement<PsiElement>(this, severity, makeMessage(a, b), element);
|
||||
}
|
||||
}
|
||||
|
||||
+35
@@ -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<A, B> extends AbstractDiagnosticFactory {
|
||||
|
||||
public static <A, B> PsiElementOnlyDiagnosticFactory2<A, B> create(Severity severity, String message) {
|
||||
return new PsiElementOnlyDiagnosticFactory2<A, B>(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<PsiElement>(this, severity, makeMessage(a, b), element);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
fun foo(u : Unit) : Int = 1
|
||||
|
||||
fun test() : Int {
|
||||
foo(<error>1</error>)
|
||||
val a : fun() : Unit = {
|
||||
foo(<error>1</error>)
|
||||
}
|
||||
return 1
|
||||
}
|
||||
Reference in New Issue
Block a user