Introduce forceResolveLazyTypes into TypeResolutionContext
The main reason is to force type resolution when resolving type arguments in class literal as annotation value argument: @Ann(Array<String>::class) class Ann `String` left unresolved unless this commit is applied. Note, that currently forced calculations used only when bare types are allowed as it's true for class literals resolution and currenlty it's enough.
This commit is contained in:
@@ -24,15 +24,27 @@ public class TypeResolutionContext {
|
||||
public final BindingTrace trace;
|
||||
public final boolean checkBounds;
|
||||
public final boolean allowBareTypes;
|
||||
public final boolean forceResolveLazyTypes;
|
||||
|
||||
public TypeResolutionContext(@NotNull JetScope scope, @NotNull BindingTrace trace, boolean checkBounds, boolean allowBareTypes) {
|
||||
this(scope, trace, checkBounds, allowBareTypes, allowBareTypes);
|
||||
}
|
||||
|
||||
private TypeResolutionContext(
|
||||
@NotNull JetScope scope,
|
||||
@NotNull BindingTrace trace,
|
||||
boolean checkBounds,
|
||||
boolean allowBareTypes,
|
||||
boolean forceResolveLazyTypes
|
||||
) {
|
||||
this.scope = scope;
|
||||
this.trace = trace;
|
||||
this.checkBounds = checkBounds;
|
||||
this.allowBareTypes = allowBareTypes;
|
||||
this.forceResolveLazyTypes = forceResolveLazyTypes;
|
||||
}
|
||||
|
||||
public TypeResolutionContext noBareTypes() {
|
||||
return new TypeResolutionContext(scope, trace, checkBounds, false);
|
||||
return new TypeResolutionContext(scope, trace, checkBounds, false, forceResolveLazyTypes);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ public class TypeResolver(
|
||||
return type(debugType)
|
||||
}
|
||||
|
||||
if (!c.allowBareTypes && lazinessToken.isLazy()) {
|
||||
if (!c.allowBareTypes && !c.forceResolveLazyTypes && lazinessToken.isLazy()) {
|
||||
// Bare types can be allowed only inside expressions; lazy type resolution is only relevant for declarations
|
||||
class LazyKotlinType : DelegatingType(), LazyEntity {
|
||||
private val _delegate = storageManager.createLazyValue { doResolvePossiblyBareType(c, typeReference).getActualType() }
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
annotation class Ann(val value: KClass<*>)
|
||||
|
||||
@Ann(Array<<error descr="[UNRESOLVED_REFERENCE] Unresolved reference: String123">String123</error>>::class) class A
|
||||
@@ -283,6 +283,12 @@ public class JetPsiCheckerTestGenerated extends AbstractJetPsiCheckerTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("ResolveTypeInAnnotationArgumentRuntime.kt")
|
||||
public void testResolveTypeInAnnotationArgumentRuntime() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/checker/ResolveTypeInAnnotationArgumentRuntime.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("ReturnTypeMismatchOnOverride.kt")
|
||||
public void testReturnTypeMismatchOnOverride() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/checker/ReturnTypeMismatchOnOverride.kt");
|
||||
|
||||
Reference in New Issue
Block a user