Fix "name in constraint is not a type parameter" diagnostic message

TO_STRING renderer was used for PSI elements, so things like "CLASS", "FUN"
were displayed in the message
This commit is contained in:
Alexander Udalov
2014-04-17 19:01:29 +04:00
parent 72dfca1698
commit a5cc894ecd
5 changed files with 23 additions and 1 deletions
@@ -347,7 +347,7 @@ public class DefaultErrorMessages {
//noinspection ConstantConditions
return typeConstraint.getSubjectTypeParameterName().getReferencedName();
}
}, TO_STRING);
}, DECLARATION_NAME);
MAP.put(AUTOCAST_IMPOSSIBLE,
"Automatic cast to ''{0}'' is impossible, because ''{1}'' could have changed since the is-check", RENDER_TYPE, STRING);
@@ -28,6 +28,7 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.psi.JetClass;
import org.jetbrains.jet.lang.psi.JetClassOrObject;
import org.jetbrains.jet.lang.psi.JetNamedDeclaration;
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
import org.jetbrains.jet.lang.resolve.calls.inference.*;
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
@@ -89,6 +90,14 @@ public class Renderers {
}
};
public static final Renderer<JetNamedDeclaration> DECLARATION_NAME = new Renderer<JetNamedDeclaration>() {
@NotNull
@Override
public String render(@NotNull JetNamedDeclaration element) {
return element.getNameAsSafeName().asString();
}
};
public static final Renderer<JetClassOrObject> RENDER_CLASS_OR_OBJECT = new Renderer<JetClassOrObject>() {
@NotNull
@Override
@@ -0,0 +1,6 @@
// !DIAGNOSTICS_NUMBER: 1
// !DIAGNOSTICS: NAME_IN_CONSTRAINT_IS_NOT_A_TYPE_PARAMETER
object O
fun <T> foo() where O : O { }
@@ -0,0 +1,2 @@
<!-- nameInConstraintIsNotATypeParameter1 -->
O does not refer to a type parameter of foo
@@ -91,6 +91,11 @@ public class DiagnosticMessageTestGenerated extends AbstractDiagnosticMessageTes
doTest("idea/testData/diagnosticMessage/multipleDefaultsFromSupertypes.kt");
}
@TestMetadata("nameInConstraintIsNotATypeParameter.kt")
public void testNameInConstraintIsNotATypeParameter() throws Exception {
doTest("idea/testData/diagnosticMessage/nameInConstraintIsNotATypeParameter.kt");
}
@TestMetadata("numberValueTypes.kt")
public void testNumberValueTypes() throws Exception {
doTest("idea/testData/diagnosticMessage/numberValueTypes.kt");