Disallow references to extensions in classes
It's not clear in which order should the two receiver arguments be passed to them, and there's no corresponding K*FunctionN class for now #KT-1183 In Progress
This commit is contained in:
@@ -345,6 +345,10 @@ public interface Errors {
|
|||||||
DiagnosticFactory1<PsiElement, InferenceErrorData> TYPE_INFERENCE_UPPER_BOUND_VIOLATED = DiagnosticFactory1.create(ERROR);
|
DiagnosticFactory1<PsiElement, InferenceErrorData> TYPE_INFERENCE_UPPER_BOUND_VIOLATED = DiagnosticFactory1.create(ERROR);
|
||||||
DiagnosticFactory2<PsiElement, JetType, JetType> TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH = DiagnosticFactory2.create(ERROR);
|
DiagnosticFactory2<PsiElement, JetType, JetType> TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH = DiagnosticFactory2.create(ERROR);
|
||||||
|
|
||||||
|
// Callable references
|
||||||
|
|
||||||
|
DiagnosticFactory1<JetExpression, CallableMemberDescriptor> EXTENSION_IN_CLASS_REFERENCE_NOT_ALLOWED = DiagnosticFactory1.create(ERROR);
|
||||||
|
|
||||||
// Multi-declarations
|
// Multi-declarations
|
||||||
|
|
||||||
DiagnosticFactory0<JetMultiDeclaration> INITIALIZER_REQUIRED_FOR_MULTIDECLARATION = DiagnosticFactory0.create(ERROR, DEFAULT);
|
DiagnosticFactory0<JetMultiDeclaration> INITIALIZER_REQUIRED_FOR_MULTIDECLARATION = DiagnosticFactory0.create(ERROR, DEFAULT);
|
||||||
|
|||||||
+3
@@ -440,6 +440,9 @@ public class DefaultErrorMessages {
|
|||||||
|
|
||||||
MAP.put(AMBIGUOUS_ANONYMOUS_TYPE_INFERRED, "Right-hand side has anonymous type. Please specify type explicitly", TO_STRING);
|
MAP.put(AMBIGUOUS_ANONYMOUS_TYPE_INFERRED, "Right-hand side has anonymous type. Please specify type explicitly", TO_STRING);
|
||||||
|
|
||||||
|
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.setImmutable();
|
MAP.setImmutable();
|
||||||
|
|
||||||
for (Field field : Errors.class.getFields()) {
|
for (Field field : Errors.class.getFields()) {
|
||||||
|
|||||||
+1
-2
@@ -611,8 +611,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
ReceiverParameterDescriptor receiverParameter = descriptor.getReceiverParameter();
|
ReceiverParameterDescriptor receiverParameter = descriptor.getReceiverParameter();
|
||||||
ReceiverParameterDescriptor expectedThisObject = descriptor.getExpectedThisObject();
|
ReceiverParameterDescriptor expectedThisObject = descriptor.getExpectedThisObject();
|
||||||
if (receiverParameter != null && expectedThisObject != null) {
|
if (receiverParameter != null && expectedThisObject != null) {
|
||||||
// TODO: report "extensions in classes" are not supported
|
context.trace.report(EXTENSION_IN_CLASS_REFERENCE_NOT_ALLOWED.on(reference, descriptor));
|
||||||
context.trace.report(UNRESOLVED_REFERENCE.on(reference, reference));
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
class A {
|
||||||
|
fun Int.extInt() = 42
|
||||||
|
fun A.extA(x: String) = x
|
||||||
|
|
||||||
|
fun main() {
|
||||||
|
::<!EXTENSION_IN_CLASS_REFERENCE_NOT_ALLOWED!>extInt<!>
|
||||||
|
::<!EXTENSION_IN_CLASS_REFERENCE_NOT_ALLOWED!>extA<!>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun main() {
|
||||||
|
A::<!EXTENSION_IN_CLASS_REFERENCE_NOT_ALLOWED!>extInt<!>
|
||||||
|
A::<!EXTENSION_IN_CLASS_REFERENCE_NOT_ALLOWED!>extA<!>
|
||||||
|
}
|
||||||
@@ -781,6 +781,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage
|
|||||||
doTest("compiler/testData/diagnostics/tests/callableReference/extensionFromTopLevel.kt");
|
doTest("compiler/testData/diagnostics/tests/callableReference/extensionFromTopLevel.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("extensionInClassDisallowed.kt")
|
||||||
|
public void testExtensionInClassDisallowed() throws Exception {
|
||||||
|
doTest("compiler/testData/diagnostics/tests/callableReference/extensionInClassDisallowed.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("genericClassFromTopLevel.kt")
|
@TestMetadata("genericClassFromTopLevel.kt")
|
||||||
public void testGenericClassFromTopLevel() throws Exception {
|
public void testGenericClassFromTopLevel() throws Exception {
|
||||||
doTest("compiler/testData/diagnostics/tests/callableReference/genericClassFromTopLevel.kt");
|
doTest("compiler/testData/diagnostics/tests/callableReference/genericClassFromTopLevel.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user