Support type annotations resolution on an underscored type argument
This commit is contained in:
+6
@@ -12861,6 +12861,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/inference"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("annotatedUnderscoredTypeArgument.kt")
|
||||
public void testAnnotatedUnderscoredTypeArgument() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/annotatedUnderscoredTypeArgument.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("cannotCompleteResolveAmbiguity.kt")
|
||||
public void testCannotCompleteResolveAmbiguity() throws Exception {
|
||||
|
||||
+6
@@ -12861,6 +12861,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/inference"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("annotatedUnderscoredTypeArgument.kt")
|
||||
public void testAnnotatedUnderscoredTypeArgument() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/annotatedUnderscoredTypeArgument.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("cannotCompleteResolveAmbiguity.kt")
|
||||
public void testCannotCompleteResolveAmbiguity() throws Exception {
|
||||
|
||||
+6
@@ -12861,6 +12861,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/inference"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("annotatedUnderscoredTypeArgument.kt")
|
||||
public void testAnnotatedUnderscoredTypeArgument() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/annotatedUnderscoredTypeArgument.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("cannotCompleteResolveAmbiguity.kt")
|
||||
public void testCannotCompleteResolveAmbiguity() throws Exception {
|
||||
|
||||
@@ -118,7 +118,7 @@ class TypeResolver(
|
||||
|
||||
val resolvedTypeSlice = if (c.abbreviated) BindingContext.ABBREVIATED_TYPE else BindingContext.TYPE
|
||||
|
||||
val annotations = resolveTypeAnnotations(c, typeReference)
|
||||
val annotations = resolveTypeAnnotations(c.trace, c.scope, typeReference)
|
||||
val type = resolveTypeElement(c, annotations, typeReference.modifierList, typeReference.typeElement)
|
||||
c.trace.recordScope(c.scope, typeReference)
|
||||
|
||||
@@ -158,7 +158,7 @@ class TypeResolver(
|
||||
}
|
||||
}
|
||||
|
||||
private fun resolveTypeAnnotations(c: TypeResolutionContext, modifierListsOwner: KtElementImplStub<*>): Annotations {
|
||||
fun resolveTypeAnnotations(trace: BindingTrace, scope: LexicalScope, modifierListsOwner: KtElementImplStub<*>): Annotations {
|
||||
val modifierLists = modifierListsOwner.getAllModifierLists()
|
||||
|
||||
var result = Annotations.EMPTY
|
||||
@@ -178,16 +178,16 @@ class TypeResolver(
|
||||
|
||||
// `targetType.stub == null` means that we don't apply this check for files that are built with stubs (that aren't opened in IDE and not in compile time)
|
||||
if (targetType is KtFunctionType && targetType.stub == null && annotationEntries != null) {
|
||||
checkNonParenthesizedAnnotationsOnFunctionalType(targetType, annotationEntries, c.trace)
|
||||
checkNonParenthesizedAnnotationsOnFunctionalType(targetType, annotationEntries, trace)
|
||||
}
|
||||
}
|
||||
|
||||
for (modifierList in modifierLists) {
|
||||
if (isSplitModifierList) {
|
||||
c.trace.report(MODIFIER_LIST_NOT_ALLOWED.on(modifierList))
|
||||
trace.report(MODIFIER_LIST_NOT_ALLOWED.on(modifierList))
|
||||
}
|
||||
|
||||
val annotations = annotationResolver.resolveAnnotationsWithoutArguments(c.scope, modifierList.annotationEntries, c.trace)
|
||||
val annotations = annotationResolver.resolveAnnotationsWithoutArguments(scope, modifierList.annotationEntries, trace)
|
||||
result = composeAnnotations(result, annotations)
|
||||
|
||||
isSplitModifierList = true
|
||||
@@ -285,7 +285,10 @@ class TypeResolver(
|
||||
c.trace.report(MODIFIER_LIST_NOT_ALLOWED.on(innerModifierList))
|
||||
}
|
||||
|
||||
val innerAnnotations = composeAnnotations(annotations, resolveTypeAnnotations(c, typeElement as KtElementImplStub<*>))
|
||||
val innerAnnotations = composeAnnotations(
|
||||
annotations,
|
||||
resolveTypeAnnotations(c.trace, c.scope, typeElement as KtElementImplStub<*>)
|
||||
)
|
||||
|
||||
return resolveTypeElement(c, innerAnnotations, outerModifierList ?: innerModifierList, innerType)
|
||||
}
|
||||
|
||||
@@ -20,8 +20,6 @@ import org.jetbrains.kotlin.resolve.calls.ArgumentTypeResolver
|
||||
import org.jetbrains.kotlin.resolve.calls.CallTransformer
|
||||
import org.jetbrains.kotlin.resolve.calls.KotlinCallResolver
|
||||
import org.jetbrains.kotlin.resolve.calls.SPECIAL_FUNCTION_NAMES
|
||||
import org.jetbrains.kotlin.resolve.calls.util.isBinaryRemOperator
|
||||
import org.jetbrains.kotlin.resolve.calls.util.*
|
||||
import org.jetbrains.kotlin.resolve.calls.components.InferenceSession
|
||||
import org.jetbrains.kotlin.resolve.calls.components.PostponedArgumentsAnalyzer
|
||||
import org.jetbrains.kotlin.resolve.calls.components.candidate.ResolutionCandidate
|
||||
@@ -37,11 +35,12 @@ import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory
|
||||
import org.jetbrains.kotlin.resolve.calls.tasks.DynamicCallableDescriptors
|
||||
import org.jetbrains.kotlin.resolve.calls.tasks.OldResolutionCandidate
|
||||
import org.jetbrains.kotlin.resolve.calls.tasks.TracingStrategy
|
||||
import org.jetbrains.kotlin.resolve.calls.util.CallMaker
|
||||
import org.jetbrains.kotlin.resolve.calls.util.*
|
||||
import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluator
|
||||
import org.jetbrains.kotlin.resolve.deprecation.DeprecationResolver
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.isUnderscoreNamed
|
||||
import org.jetbrains.kotlin.resolve.lazy.ForceResolveUtil
|
||||
import org.jetbrains.kotlin.resolve.scopes.*
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.*
|
||||
import org.jetbrains.kotlin.types.*
|
||||
@@ -687,9 +686,14 @@ class PSICallResolver(
|
||||
}
|
||||
ModifierCheckerCore.check(projection, context.trace, null, languageVersionSettings)
|
||||
|
||||
val typeReference = projection.typeReference
|
||||
val typeReference = projection.typeReference ?: return@map TypeArgumentPlaceholder
|
||||
|
||||
if (typeReference == null || typeReference.isPlaceholder) return@map TypeArgumentPlaceholder
|
||||
if (typeReference.isPlaceholder) {
|
||||
ForceResolveUtil.forceResolveAllContents(
|
||||
typeResolver.resolveTypeAnnotations(context.trace, context.scope, typeReference)
|
||||
)
|
||||
return@map TypeArgumentPlaceholder
|
||||
}
|
||||
|
||||
SimpleTypeArgumentImpl(projection, resolveType(context, typeReference, typeResolver))
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ class KtTypeReference : KtModifierListOwnerStub<KotlinPlaceHolderStub<KtTypeRefe
|
||||
}
|
||||
|
||||
val isPlaceholder: Boolean
|
||||
get() = findDescendantOfType<KtNameReferenceExpression>()?.isPlaceholder == true
|
||||
get() = typeElement?.findDescendantOfType<KtNameReferenceExpression>()?.isPlaceholder == true
|
||||
|
||||
val typeElement: KtTypeElement?
|
||||
get() = KtStubbedPsiUtil.getStubOrPsiChild(this, KtStubElementTypes.TYPE_ELEMENT_TYPES, KtTypeElement.ARRAY_FACTORY)
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// !DIAGNOSTICS: -UNCHECKED_CAST
|
||||
// FIR_IDENTICAL
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun <K, T> foo(x: (K) -> T): Pair<K, T> = (1 as K) to (1f as T)
|
||||
|
||||
@Target(AnnotationTarget.TYPE)
|
||||
annotation class Anno
|
||||
|
||||
fun box(): String {
|
||||
val x = foo<@Anno Int, @Anno _> { it.toFloat() }
|
||||
return "OK"
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package
|
||||
|
||||
public fun box(): kotlin.String
|
||||
public fun </*0*/ K, /*1*/ T> foo(/*0*/ x: (K) -> T): kotlin.Pair<K, T>
|
||||
|
||||
@kotlin.annotation.Target(allowedTargets = {AnnotationTarget.TYPE}) public final annotation class Anno : kotlin.Annotation {
|
||||
public constructor Anno()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
Generated
+6
@@ -12867,6 +12867,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/inference"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("annotatedUnderscoredTypeArgument.kt")
|
||||
public void testAnnotatedUnderscoredTypeArgument() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/annotatedUnderscoredTypeArgument.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("cannotCompleteResolveAmbiguity.kt")
|
||||
public void testCannotCompleteResolveAmbiguity() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user