diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index 2c3e80fb93d..6038b860a50 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -81,6 +81,7 @@ public interface Errors { DiagnosticFactory0 UNSUPPORTED_SEALED_WHEN = DiagnosticFactory0.create(ERROR); DiagnosticFactory0 UNSUPPORTED_SEALED_FUN_INTERFACE = DiagnosticFactory0.create(ERROR); DiagnosticFactory0 UNSUPPORTED_SUSPEND_TEST = DiagnosticFactory0.create(ERROR); + DiagnosticFactory0 UNSUPPORTED_REFERENCES_TO_VARIABLES_AND_PARAMETERS = DiagnosticFactory0.create(ERROR); //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java index 6368a713dca..daf83e01a7d 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java @@ -829,6 +829,7 @@ public class DefaultErrorMessages { MAP.put(UNSUPPORTED_SEALED_WHEN, "'sealed' in front of 'when' is reserved"); MAP.put(UNSUPPORTED_SEALED_FUN_INTERFACE, "'sealed fun interface' is unsupported"); MAP.put(UNSUPPORTED_SUSPEND_TEST, "'suspend' functions annotated with @kotlin.test.Test are unsupported"); + MAP.put(UNSUPPORTED_REFERENCES_TO_VARIABLES_AND_PARAMETERS, "References to variables and parameters are unsupported"); MAP.put(EXCEPTION_FROM_ANALYZER, "Internal Error occurred while analyzing this expression:\n{0}", THROWABLE); MAP.put(MISSING_STDLIB, "{0}. Ensure you have the standard Kotlin library in dependencies", STRING); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/DoubleColonExpressionResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/DoubleColonExpressionResolver.kt index 32ff7acf072..3fb1d1624eb 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/DoubleColonExpressionResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/DoubleColonExpressionResolver.kt @@ -614,7 +614,7 @@ class DoubleColonExpressionResolver( trace.report(EXTENSION_IN_CLASS_REFERENCE_NOT_ALLOWED.on(simpleName, descriptor)) } if (descriptor is VariableDescriptor && descriptor !is PropertyDescriptor) { - trace.report(UNSUPPORTED.on(simpleName, "References to variables aren't supported yet")) + trace.report(UNSUPPORTED_REFERENCES_TO_VARIABLES_AND_PARAMETERS.on(simpleName)) } } diff --git a/compiler/testData/diagnostics/tests/callableReference/property/backingField.fir.kt b/compiler/testData/diagnostics/tests/callableReference/property/backingField.fir.kt new file mode 100644 index 00000000000..3b9d69bf7f8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/callableReference/property/backingField.fir.kt @@ -0,0 +1,7 @@ +// !DIAGNOSTICS: -UNUSED_EXPRESSION + +val i: Int = 10 + get() { + ::field + return field + } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/property/backingField.kt b/compiler/testData/diagnostics/tests/callableReference/property/backingField.kt index df609f877af..85720708e42 100644 --- a/compiler/testData/diagnostics/tests/callableReference/property/backingField.kt +++ b/compiler/testData/diagnostics/tests/callableReference/property/backingField.kt @@ -1,8 +1,7 @@ -// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_EXPRESSION val i: Int = 10 get() { - ::field + ::field return field } diff --git a/compiler/testData/diagnostics/tests/callableReference/unsupported/callableReferenceToLocalVariable.kt b/compiler/testData/diagnostics/tests/callableReference/unsupported/callableReferenceToLocalVariable.kt index 52bb500a641..6933f5fb9e9 100644 --- a/compiler/testData/diagnostics/tests/callableReference/unsupported/callableReferenceToLocalVariable.kt +++ b/compiler/testData/diagnostics/tests/callableReference/unsupported/callableReferenceToLocalVariable.kt @@ -3,14 +3,14 @@ fun a() { val x = 10 - foo(::x) + foo(::x) } fun foo(a: Any) {} fun test1(test2: () -> Unit = ::test2) {} // Resolve to function private fun test2() {} -fun test3(test4: () -> Unit = ::test4) {} +fun test3(test4: () -> Unit = ::test4) {} fun test5(test6: (test: Test) -> Unit = Test::helper) { test6(Test()) diff --git a/compiler/testData/diagnostics/tests/callableReference/unsupported/localVariable.kt b/compiler/testData/diagnostics/tests/callableReference/unsupported/localVariable.kt index 3639382638e..139e03f1eb0 100644 --- a/compiler/testData/diagnostics/tests/callableReference/unsupported/localVariable.kt +++ b/compiler/testData/diagnostics/tests/callableReference/unsupported/localVariable.kt @@ -3,13 +3,13 @@ fun eat(value: Any) {} fun test(param: String) { - val a = ::param + val a = ::param val local = "local" - val b = ::local + val b = ::local val lambda = { -> } - val g = ::lambda + val g = ::lambda - eat(::param) + eat(::param) } diff --git a/compiler/testData/diagnostics/tests/callableReference/unsupported/localVariableWithSubstitution.kt b/compiler/testData/diagnostics/tests/callableReference/unsupported/localVariableWithSubstitution.kt index 401b1b31817..9b5bbc5f928 100644 --- a/compiler/testData/diagnostics/tests/callableReference/unsupported/localVariableWithSubstitution.kt +++ b/compiler/testData/diagnostics/tests/callableReference/unsupported/localVariableWithSubstitution.kt @@ -9,6 +9,6 @@ class Foo { fun main() { val f = Foo() val a: Int - get() = f.getValue(null, ::a) // no exception after fix + get() = f.getValue(null, ::a) // no exception after fix print(a) } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/unsupported/parameterWithSubstitution.kt b/compiler/testData/diagnostics/tests/callableReference/unsupported/parameterWithSubstitution.kt index cdec100f59e..bceaf68c116 100644 --- a/compiler/testData/diagnostics/tests/callableReference/unsupported/parameterWithSubstitution.kt +++ b/compiler/testData/diagnostics/tests/callableReference/unsupported/parameterWithSubstitution.kt @@ -9,6 +9,6 @@ class Foo { fun main(x: Int) { val f = Foo() val a: Int - get() = f.getValue(null, ::x) // no exception after fix + get() = f.getValue(null, ::x) // no exception after fix print(a) } diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/callableReferenceOnParameter.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/callableReferenceOnParameter.kt index e21b7e3103f..2367977f0d0 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/inference/callableReferenceOnParameter.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/callableReferenceOnParameter.kt @@ -3,6 +3,6 @@ internal class Z { val map = HashMap() inline fun compute(key: String, producer: () -> String): String { - return map.getOrPut(key, ::producer) + return map.getOrPut(key, ::producer) } }