diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSICallResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSICallResolver.kt index a1215385bd1..8325913c810 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSICallResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSICallResolver.kt @@ -745,7 +745,13 @@ class PSICallResolver( is DoubleColonLHS.Type -> { val qualifiedExpression = ktExpression.receiverExpression!! val qualifier = expressionTypingContext.trace.get(BindingContext.QUALIFIER, qualifiedExpression) - LHSResult.Type(qualifier, lhsResult.type.unwrap()) + val classifier = lhsResult.type.constructor.declarationDescriptor + if (classifier !is ClassDescriptor) { + expressionTypingContext.trace.report(Errors.CALLABLE_REFERENCE_LHS_NOT_A_CLASS.on(ktExpression)) + LHSResult.Error + } else { + LHSResult.Type(qualifier, lhsResult.type.unwrap()) + } } } diff --git a/compiler/testData/diagnostics/tests/callableReference/function/lhsNotAClass.fir.kt b/compiler/testData/diagnostics/tests/callableReference/function/lhsNotAClass.fir.kt index f4f652c3b83..af2b7e5bc06 100644 --- a/compiler/testData/diagnostics/tests/callableReference/function/lhsNotAClass.fir.kt +++ b/compiler/testData/diagnostics/tests/callableReference/function/lhsNotAClass.fir.kt @@ -1,9 +1,19 @@ +// !WITH_NEW_INFERENCE + class A { fun foo() = T::toString fun bar() = U::toString + + fun baz() { + take(T::toString) + + take(U::toString) + } } fun foo() = T::toString fun bar() = U::toString + +fun take(arg: Any) {} diff --git a/compiler/testData/diagnostics/tests/callableReference/function/lhsNotAClass.kt b/compiler/testData/diagnostics/tests/callableReference/function/lhsNotAClass.kt index 402624292cf..23e721dc794 100644 --- a/compiler/testData/diagnostics/tests/callableReference/function/lhsNotAClass.kt +++ b/compiler/testData/diagnostics/tests/callableReference/function/lhsNotAClass.kt @@ -1,9 +1,19 @@ +// !WITH_NEW_INFERENCE + class A { fun foo() = T::toString fun bar() = U::toString + + fun baz() { + take(T::toString) + + take(U::toString) + } } fun foo() = T::toString fun bar() = U::toString + +fun take(arg: Any) {} diff --git a/compiler/testData/diagnostics/tests/callableReference/function/lhsNotAClass.txt b/compiler/testData/diagnostics/tests/callableReference/function/lhsNotAClass.txt index 7746d2d9b7e..398d2d34365 100644 --- a/compiler/testData/diagnostics/tests/callableReference/function/lhsNotAClass.txt +++ b/compiler/testData/diagnostics/tests/callableReference/function/lhsNotAClass.txt @@ -2,10 +2,12 @@ package public fun bar(): [ERROR : Error function type] public fun foo(): [ERROR : Error function type] +public fun take(/*0*/ arg: kotlin.Any): kotlin.Unit public final class A { public constructor A() public final fun bar(): [ERROR : Error function type] + public final fun baz(): kotlin.Unit public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean public final fun foo(): [ERROR : Error function type] public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int