Report error instead of assertion when property is used as operator

#KT-34857 fixed
This commit is contained in:
Ilya Chernikov
2020-01-24 12:36:34 +01:00
parent a1acb4afaf
commit 9623b0eedb
9 changed files with 43 additions and 1 deletions
@@ -328,6 +328,11 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte
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")
public void testKt435() throws Exception {
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> 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);
@@ -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. " +
@@ -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}" +
+8
View File
@@ -0,0 +1,8 @@
// !LANGUAGE: +NewInference
val Int.plusAssign: (Int) -> Unit
get() = {}
fun main() {
1 <!PROPERTY_AS_OPERATOR!>+=<!> 2
}
+8
View File
@@ -0,0 +1,8 @@
// !LANGUAGE: +NewInference
val Int.plusAssign: (Int) -> Unit
get() = {}
fun main() {
1 <!PROPERTY_AS_OPERATOR!>+=<!> 2
}
+4
View File
@@ -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");
}
@TestMetadata("kt34857.kt")
public void testKt34857() throws Exception {
runTest("compiler/testData/diagnostics/tests/kt34857.kt");
}
@TestMetadata("kt435.kt")
public void testKt435() throws Exception {
runTest("compiler/testData/diagnostics/tests/kt435.kt");
@@ -330,6 +330,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
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")
public void testKt435() throws Exception {
runTest("compiler/testData/diagnostics/tests/kt435.kt");