Report error instead of assertion when property is used as operator
#KT-34857 fixed
This commit is contained in:
@@ -867,6 +867,8 @@ public interface Errors {
|
||||
DiagnosticFactory2<PsiElement, FunctionDescriptor, String> OPERATOR_MODIFIER_REQUIRED = DiagnosticFactory2.create(ERROR);
|
||||
DiagnosticFactory2<PsiElement, FunctionDescriptor, String> INFIX_MODIFIER_REQUIRED = DiagnosticFactory2.create(ERROR);
|
||||
|
||||
DiagnosticFactory2<PsiElement, FunctionDescriptor, String> PROPERTY_AS_OPERATOR = DiagnosticFactory2.create(ERROR);
|
||||
|
||||
DiagnosticFactory2<PsiElement, KtModifierKeywordToken, String> INAPPLICABLE_MODIFIER = DiagnosticFactory2.create(ERROR);
|
||||
|
||||
DiagnosticFactory1<PsiElement, CallableDescriptor> DSL_SCOPE_VIOLATION = DiagnosticFactory1.create(ERROR);
|
||||
|
||||
+2
@@ -504,6 +504,8 @@ public class DefaultErrorMessages {
|
||||
MAP.put(OPERATOR_MODIFIER_REQUIRED, "''operator'' modifier is required on ''{0}'' in ''{1}''", NAME, STRING);
|
||||
MAP.put(INFIX_MODIFIER_REQUIRED, "''infix'' modifier is required on ''{0}'' in ''{1}''", NAME, STRING);
|
||||
|
||||
MAP.put(PROPERTY_AS_OPERATOR, "Properties cannot be used in operator conventions: ''{0}'' in ''{1}''", NAME, STRING);
|
||||
|
||||
MAP.put(INAPPLICABLE_MODIFIER, "''{0}'' modifier is inapplicable. The reason is that {1}", TO_STRING, STRING);
|
||||
|
||||
MAP.put(DSL_SCOPE_VIOLATION, "''{0}'' can''t be called in this context by implicit receiver. " +
|
||||
|
||||
+4
-1
@@ -48,7 +48,10 @@ class OperatorCallChecker : CallChecker {
|
||||
if (resolvedCall is VariableAsFunctionResolvedCall &&
|
||||
call is CallTransformer.CallForImplicitInvoke && call.itIsVariableAsFunctionCall) {
|
||||
val outerCall = call.outerCall
|
||||
if (isConventionCall(outerCall) || isWrongCallWithExplicitTypeArguments(resolvedCall, outerCall)) {
|
||||
if (isConventionCall(outerCall)) {
|
||||
val containingDeclarationName = functionDescriptor.containingDeclaration.fqNameUnsafe.asString()
|
||||
context.trace.report(Errors.PROPERTY_AS_OPERATOR.on(reportOn, functionDescriptor, containingDeclarationName))
|
||||
} else if (isWrongCallWithExplicitTypeArguments(resolvedCall, outerCall)) {
|
||||
throw AssertionError(
|
||||
"Illegal resolved call to variable with invoke for $outerCall. " +
|
||||
"Variable: ${resolvedCall.variableCall.resultingDescriptor}" +
|
||||
|
||||
Reference in New Issue
Block a user