diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/CopyUtils.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/CopyUtils.kt index aed3244e4cd..45ced0bc38f 100644 --- a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/CopyUtils.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/CopyUtils.kt @@ -73,6 +73,7 @@ fun List.computeTypeAttributes( session: FirSession, predefined: List> = emptyList(), containerDeclaration: FirDeclaration? = null, + allowExtensionFunctionType: Boolean = true, shouldExpandTypeAliases: Boolean ): ConeAttributes { if (this.isEmpty()) { @@ -90,7 +91,9 @@ fun List.computeTypeAttributes( when (classId) { CompilerConeAttributes.Exact.ANNOTATION_CLASS_ID -> attributes += CompilerConeAttributes.Exact CompilerConeAttributes.NoInfer.ANNOTATION_CLASS_ID -> attributes += CompilerConeAttributes.NoInfer - CompilerConeAttributes.ExtensionFunctionType.ANNOTATION_CLASS_ID -> attributes += CompilerConeAttributes.ExtensionFunctionType + CompilerConeAttributes.ExtensionFunctionType.ANNOTATION_CLASS_ID -> when { + allowExtensionFunctionType -> attributes += CompilerConeAttributes.ExtensionFunctionType + } CompilerConeAttributes.ContextFunctionTypeParams.ANNOTATION_CLASS_ID -> attributes += CompilerConeAttributes.ContextFunctionTypeParams( diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/providers/impl/FirTypeResolverImpl.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/providers/impl/FirTypeResolverImpl.kt index 976989a0934..48407b72d2d 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/providers/impl/FirTypeResolverImpl.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/providers/impl/FirTypeResolverImpl.kt @@ -20,6 +20,7 @@ import org.jetbrains.kotlin.fir.resolve.calls.ResolutionDiagnostic import org.jetbrains.kotlin.fir.resolve.diagnostics.* import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor import org.jetbrains.kotlin.fir.resolve.transformers.ScopeClassDeclaration +import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol import org.jetbrains.kotlin.fir.symbols.SymbolInternals import org.jetbrains.kotlin.fir.symbols.impl.* @@ -260,7 +261,12 @@ class FirTypeResolverImpl(private val session: FirSession) : FirTypeResolver() { return symbol.constructType( resultingArguments, typeRef.isMarkedNullable, - typeRef.annotations.computeTypeAttributes(session, containerDeclaration = containerDeclaration, shouldExpandTypeAliases = true) + typeRef.annotations.computeTypeAttributes( + session, + containerDeclaration = containerDeclaration, + shouldExpandTypeAliases = true, + allowExtensionFunctionType = (symbol.toLookupTag() as? ConeClassLikeLookupTag)?.isSomeFunctionType(session) == true, + ) ).also { val lookupTag = it.lookupTag if (lookupTag is ConeClassLikeLookupTagImpl && symbol is FirClassLikeSymbol<*>) { diff --git a/compiler/testData/diagnostics/tests/FreeFunctionCalledAsExtension.fir.kt b/compiler/testData/diagnostics/tests/FreeFunctionCalledAsExtension.fir.kt deleted file mode 100644 index 140ff3919a6..00000000000 --- a/compiler/testData/diagnostics/tests/FreeFunctionCalledAsExtension.fir.kt +++ /dev/null @@ -1,14 +0,0 @@ -fun foo(a: (String) -> Unit) { - "".a() -} - - - -interface A : (String) -> Unit {} -typealias AliasedEFT = ExtensionFunctionType - -fun foo(a: @AliasedEFT A) { - // @Extension annotation on an unrelated type shouldn't have any effect on this diagnostic. - // Only kotlin.Function{n} type annotated with @Extension should - "".a() -} diff --git a/compiler/testData/diagnostics/tests/FreeFunctionCalledAsExtension.kt b/compiler/testData/diagnostics/tests/FreeFunctionCalledAsExtension.kt index b742d3ccb3c..60d57dcb207 100644 --- a/compiler/testData/diagnostics/tests/FreeFunctionCalledAsExtension.kt +++ b/compiler/testData/diagnostics/tests/FreeFunctionCalledAsExtension.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL fun foo(a: (String) -> Unit) { "".a() } diff --git a/compiler/testData/diagnostics/tests/FreeFunctionCalledAsExtension.reversed.kt b/compiler/testData/diagnostics/tests/FreeFunctionCalledAsExtension.reversed.kt deleted file mode 100644 index b742d3ccb3c..00000000000 --- a/compiler/testData/diagnostics/tests/FreeFunctionCalledAsExtension.reversed.kt +++ /dev/null @@ -1,14 +0,0 @@ -fun foo(a: (String) -> Unit) { - "".a() -} - - - -interface A : (String) -> Unit {} -typealias AliasedEFT = ExtensionFunctionType - -fun foo(a: @AliasedEFT A) { - // @Extension annotation on an unrelated type shouldn't have any effect on this diagnostic. - // Only kotlin.Function{n} type annotated with @Extension should - "".a() -}