LHS of callable reference can't be a type parameter

This commit is contained in:
Alexander Udalov
2013-04-18 19:56:51 +04:00
parent d40906a690
commit fee7846c7e
5 changed files with 20 additions and 2 deletions
@@ -348,6 +348,7 @@ public interface Errors {
// Callable references
DiagnosticFactory1<JetExpression, CallableMemberDescriptor> EXTENSION_IN_CLASS_REFERENCE_NOT_ALLOWED = DiagnosticFactory1.create(ERROR);
DiagnosticFactory0<JetExpression> CALLABLE_REFERENCE_LHS_NOT_A_CLASS = DiagnosticFactory0.create(ERROR);
// Multi-declarations
@@ -442,6 +442,7 @@ public class DefaultErrorMessages {
MAP.put(EXTENSION_IN_CLASS_REFERENCE_NOT_ALLOWED,
"''{0}'' is a member and an extension at the same time. References to such elements are not allowed", TO_STRING);
MAP.put(CALLABLE_REFERENCE_LHS_NOT_A_CLASS, "Callable reference left-hand side cannot be a type parameter");
MAP.setImmutable();
@@ -657,8 +657,10 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
}
ClassifierDescriptor classifier = lhsType.getConstructor().getDeclarationDescriptor();
// TODO: report an error if the classifier is not a class
assert classifier instanceof ClassDescriptor : "TODO";
if (!(classifier instanceof ClassDescriptor)) {
context.trace.report(CALLABLE_REFERENCE_LHS_NOT_A_CLASS.on(expression));
return null;
}
ReceiverValue receiver = new TransientReceiver(lhsType);
TemporaryBindingTrace traceWithReceiver = TemporaryBindingTrace.create(context.trace,
@@ -0,0 +1,9 @@
class A<T, U : Any> {
fun foo() = <!CALLABLE_REFERENCE_LHS_NOT_A_CLASS!>T::<!UNRESOLVED_REFERENCE!>toString<!><!>
fun bar() = <!CALLABLE_REFERENCE_LHS_NOT_A_CLASS!>U::<!UNRESOLVED_REFERENCE!>toString<!><!>
}
fun <T> foo() = <!CALLABLE_REFERENCE_LHS_NOT_A_CLASS!>T::<!UNRESOLVED_REFERENCE!>toString<!><!>
fun <U : Any> bar() = <!CALLABLE_REFERENCE_LHS_NOT_A_CLASS!>U::<!UNRESOLVED_REFERENCE!>toString<!><!>
@@ -811,6 +811,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage
doTest("compiler/testData/diagnostics/tests/callableReference/innerConstructorFromTopLevel.kt");
}
@TestMetadata("lhsNotAClass.kt")
public void testLhsNotAClass() throws Exception {
doTest("compiler/testData/diagnostics/tests/callableReference/lhsNotAClass.kt");
}
@TestMetadata("localConstructor.kt")
public void testLocalConstructor() throws Exception {
doTest("compiler/testData/diagnostics/tests/callableReference/localConstructor.kt");