[FIR] Only support @ExtensionFunctionType on true functional types
^KT-59874
This commit is contained in:
committed by
Space Team
parent
6210da0c98
commit
4b67a504be
@@ -73,6 +73,7 @@ fun List<FirAnnotation>.computeTypeAttributes(
|
||||
session: FirSession,
|
||||
predefined: List<ConeAttribute<*>> = emptyList(),
|
||||
containerDeclaration: FirDeclaration? = null,
|
||||
allowExtensionFunctionType: Boolean = true,
|
||||
shouldExpandTypeAliases: Boolean
|
||||
): ConeAttributes {
|
||||
if (this.isEmpty()) {
|
||||
@@ -90,7 +91,9 @@ fun List<FirAnnotation>.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(
|
||||
|
||||
+7
-1
@@ -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<*>) {
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
fun foo(a: (String) -> Unit) {
|
||||
"".<!UNRESOLVED_REFERENCE!>a<!>()
|
||||
}
|
||||
|
||||
|
||||
|
||||
interface A : (String) -> Unit {}
|
||||
typealias AliasedEFT = ExtensionFunctionType
|
||||
|
||||
fun foo(a: <!WRONG_EXTENSION_FUNCTION_TYPE!>@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()
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
fun foo(a: (String) -> Unit) {
|
||||
"".<!UNRESOLVED_REFERENCE!>a<!>()
|
||||
}
|
||||
|
||||
-14
@@ -1,14 +0,0 @@
|
||||
fun foo(a: (String) -> Unit) {
|
||||
"".<!UNRESOLVED_REFERENCE!>a<!>()
|
||||
}
|
||||
|
||||
|
||||
|
||||
interface A : (String) -> Unit {}
|
||||
typealias AliasedEFT = ExtensionFunctionType
|
||||
|
||||
fun foo(a: <!WRONG_EXTENSION_FUNCTION_TYPE!>@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
|
||||
"".<!UNRESOLVED_REFERENCE!>a<!>()
|
||||
}
|
||||
Reference in New Issue
Block a user