Report error instead of assertion when property is used as operator
#KT-34857 fixed
This commit is contained in:
Generated
+5
@@ -328,6 +328,11 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte
|
|||||||
runTest("compiler/testData/diagnostics/tests/kt310.kt");
|
runTest("compiler/testData/diagnostics/tests/kt310.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt34857.kt")
|
||||||
|
public void testKt34857() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/kt34857.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt435.kt")
|
@TestMetadata("kt435.kt")
|
||||||
public void testKt435() throws Exception {
|
public void testKt435() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/tests/kt435.kt");
|
runTest("compiler/testData/diagnostics/tests/kt435.kt");
|
||||||
|
|||||||
@@ -867,6 +867,8 @@ public interface Errors {
|
|||||||
DiagnosticFactory2<PsiElement, FunctionDescriptor, String> OPERATOR_MODIFIER_REQUIRED = DiagnosticFactory2.create(ERROR);
|
DiagnosticFactory2<PsiElement, FunctionDescriptor, String> OPERATOR_MODIFIER_REQUIRED = DiagnosticFactory2.create(ERROR);
|
||||||
DiagnosticFactory2<PsiElement, FunctionDescriptor, String> INFIX_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);
|
DiagnosticFactory2<PsiElement, KtModifierKeywordToken, String> INAPPLICABLE_MODIFIER = DiagnosticFactory2.create(ERROR);
|
||||||
|
|
||||||
DiagnosticFactory1<PsiElement, CallableDescriptor> DSL_SCOPE_VIOLATION = DiagnosticFactory1.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(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(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(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. " +
|
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 &&
|
if (resolvedCall is VariableAsFunctionResolvedCall &&
|
||||||
call is CallTransformer.CallForImplicitInvoke && call.itIsVariableAsFunctionCall) {
|
call is CallTransformer.CallForImplicitInvoke && call.itIsVariableAsFunctionCall) {
|
||||||
val outerCall = call.outerCall
|
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(
|
throw AssertionError(
|
||||||
"Illegal resolved call to variable with invoke for $outerCall. " +
|
"Illegal resolved call to variable with invoke for $outerCall. " +
|
||||||
"Variable: ${resolvedCall.variableCall.resultingDescriptor}" +
|
"Variable: ${resolvedCall.variableCall.resultingDescriptor}" +
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
// !LANGUAGE: +NewInference
|
||||||
|
|
||||||
|
val Int.plusAssign: (Int) -> Unit
|
||||||
|
get() = {}
|
||||||
|
|
||||||
|
fun main() {
|
||||||
|
1 <!PROPERTY_AS_OPERATOR!>+=<!> 2
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
// !LANGUAGE: +NewInference
|
||||||
|
|
||||||
|
val Int.plusAssign: (Int) -> Unit
|
||||||
|
get() = {}
|
||||||
|
|
||||||
|
fun main() {
|
||||||
|
1 <!PROPERTY_AS_OPERATOR!>+=<!> 2
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
public val kotlin.Int.plusAssign: (kotlin.Int) -> kotlin.Unit
|
||||||
|
public fun main(): kotlin.Unit
|
||||||
@@ -330,6 +330,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
|||||||
runTest("compiler/testData/diagnostics/tests/kt310.kt");
|
runTest("compiler/testData/diagnostics/tests/kt310.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt34857.kt")
|
||||||
|
public void testKt34857() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/kt34857.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt435.kt")
|
@TestMetadata("kt435.kt")
|
||||||
public void testKt435() throws Exception {
|
public void testKt435() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/tests/kt435.kt");
|
runTest("compiler/testData/diagnostics/tests/kt435.kt");
|
||||||
|
|||||||
Generated
+5
@@ -330,6 +330,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
|
|||||||
runTest("compiler/testData/diagnostics/tests/kt310.kt");
|
runTest("compiler/testData/diagnostics/tests/kt310.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt34857.kt")
|
||||||
|
public void testKt34857() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/kt34857.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt435.kt")
|
@TestMetadata("kt435.kt")
|
||||||
public void testKt435() throws Exception {
|
public void testKt435() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/tests/kt435.kt");
|
runTest("compiler/testData/diagnostics/tests/kt435.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user