Prohibit super delegation call if there is primary constructor
This commit is contained in:
@@ -158,6 +158,7 @@ public interface Errors {
|
||||
DiagnosticFactory0<JetConstructorDelegationCall> CYCLIC_CONSTRUCTOR_DELEGATION_CALL = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<JetSecondaryConstructor> SECONDARY_CONSTRUCTOR_IN_OBJECT = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<JetDelegatorToSuperCall> SUPERTYPE_INITIALIZED_WITHOUT_PRIMARY_CONSTRUCTOR = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<JetConstructorDelegationCall> PRIMARY_CONSTRUCTOR_DELEGATION_CALL_EXPECTED = DiagnosticFactory0.create(ERROR);
|
||||
|
||||
// Trait-specific
|
||||
|
||||
|
||||
+1
@@ -416,6 +416,7 @@ public class DefaultErrorMessages {
|
||||
MAP.put(CYCLIC_CONSTRUCTOR_DELEGATION_CALL, "There's a cycle in the delegation calls chain");
|
||||
MAP.put(SECONDARY_CONSTRUCTOR_IN_OBJECT, "Constructors are not allowed for objects");
|
||||
MAP.put(SUPERTYPE_INITIALIZED_WITHOUT_PRIMARY_CONSTRUCTOR, "Supertype initialization is impossible without primary constructor");
|
||||
MAP.put(PRIMARY_CONSTRUCTOR_DELEGATION_CALL_EXPECTED, "Primary constructor call expected");
|
||||
|
||||
MAP.put(ILLEGAL_SELECTOR, "Expression ''{0}'' cannot be a selector (occur after a dot)", STRING);
|
||||
|
||||
|
||||
@@ -52,6 +52,7 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.kotlin.diagnostics.Errors.EXPECTED_PRIMARY_CONSTRUCTOR_DELEGATION_CALL;
|
||||
import static org.jetbrains.kotlin.diagnostics.Errors.NOT_A_CLASS;
|
||||
import static org.jetbrains.kotlin.diagnostics.Errors.NO_CONSTRUCTOR;
|
||||
import static org.jetbrains.kotlin.resolve.bindingContextUtil.BindingContextUtilPackage.recordScopeAndDataFlowInfo;
|
||||
@@ -301,6 +302,12 @@ public class CallResolver {
|
||||
DescriptorUtilPackage.getSuperClassOrAny(currentClassDescriptor);
|
||||
Collection<ConstructorDescriptor> constructors = delegateClassDescriptor.getConstructors();
|
||||
|
||||
if (!calleeExpression.isThis() && currentClassDescriptor.getUnsubstitutedPrimaryConstructor() != null) {
|
||||
context.trace.report(PRIMARY_CONSTRUCTOR_DELEGATION_CALL_EXPECTED.on(
|
||||
(JetConstructorDelegationCall) calleeExpression.getParent()
|
||||
));
|
||||
}
|
||||
|
||||
if (constructors.isEmpty()) {
|
||||
context.trace.report(NO_CONSTRUCTOR.on(CallUtilPackage.getValueArgumentListOrElement(context.call)));
|
||||
return checkArgumentTypesAndFail(context);
|
||||
|
||||
Reference in New Issue
Block a user