Make not-null compile-time constants non-flexible

This commit is contained in:
Andrey Breslav
2014-08-10 21:20:15 +04:00
parent 867956729b
commit c699fa96d9
3 changed files with 20 additions and 2 deletions
@@ -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
}
@@ -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);
}