Make not-null compile-time constants non-flexible
This commit is contained in:
+10
-2
@@ -287,10 +287,18 @@ public abstract class LazyJavaMemberScope(
|
||||
|
||||
private fun getPropertyType(field: JavaField): JetType {
|
||||
// Fields do not have their own generic parameters
|
||||
val propertyType = c.typeResolver.transformJavaType(field.getType(), LazyJavaTypeAttributes(c, field, TypeUsage.MEMBER_SIGNATURE_INVARIANT))
|
||||
if (!PLATFORM_TYPES && field.isFinal() && field.isStatic()) {
|
||||
val finalStatic = field.isFinal() && field.isStatic()
|
||||
|
||||
// simple static constants should not have flexible types:
|
||||
val allowFlexible = PLATFORM_TYPES && !(finalStatic && c.javaPropertyInitializerEvaluator.isNotNullCompileTimeConstant(field))
|
||||
val propertyType = c.typeResolver.transformJavaType(
|
||||
field.getType(),
|
||||
LazyJavaTypeAttributes(c, field, TypeUsage.MEMBER_SIGNATURE_INVARIANT, allowFlexible)
|
||||
)
|
||||
if ((!allowFlexible || !PLATFORM_TYPES) && finalStatic) {
|
||||
return TypeUtils.makeNotNullable(propertyType)
|
||||
}
|
||||
|
||||
return propertyType
|
||||
}
|
||||
|
||||
|
||||
+2
@@ -24,4 +24,6 @@ import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
|
||||
public interface JavaPropertyInitializerEvaluator {
|
||||
@Nullable
|
||||
CompileTimeConstant<?> getInitializerConstant(@NotNull JavaField field, @NotNull PropertyDescriptor descriptor);
|
||||
|
||||
boolean isNotNullCompileTimeConstant(@NotNull JavaField field);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user