Provide fallback flag for KT-19174

-Xno-exception-on-explicit-equals-for-boxed-null

Also unify corresponding names.
This commit is contained in:
Dmitry Petrov
2017-09-12 16:08:03 +03:00
parent 773eff1de8
commit 179e720e4a
12 changed files with 79 additions and 6 deletions
@@ -37,7 +37,7 @@ class Equals : IntrinsicMethod() {
}
}
class ConsistentEquals(private val lhsType: Type) : IntrinsicMethod() {
class EqualsThrowingNpeForNullReceiver(private val lhsType: Type) : IntrinsicMethod() {
override fun toCallable(method: CallableMethod): Callable =
createBinaryIntrinsicCallable(
method.returnType,
@@ -65,7 +65,7 @@ public class IntrinsicMethods {
this(jvmTarget, true);
}
public IntrinsicMethods(JvmTarget jvmTarget, boolean useConsistentEqualsForPrimitiveWrappers) {
public IntrinsicMethods(JvmTarget jvmTarget, boolean shouldThrowNpeOnExplicitEqualsForBoxedNull) {
intrinsicsMap.registerIntrinsic(KOTLIN_JVM, RECEIVER_PARAMETER_FQ_NAME, "javaClass", -1, JavaClassProperty.INSTANCE);
intrinsicsMap.registerIntrinsic(KOTLIN_JVM, KotlinBuiltIns.FQ_NAMES.kClass, "java", -1, new KClassJavaProperty());
intrinsicsMap.registerIntrinsic(KotlinBuiltIns.FQ_NAMES.kCallable.toSafe(), null, "name", -1, new KCallableNameProperty());
@@ -102,9 +102,9 @@ public class IntrinsicMethods {
for (PrimitiveType type : PrimitiveType.values()) {
FqName typeFqName = type.getTypeFqName();
IntrinsicMethod equalsMethod;
if (useConsistentEqualsForPrimitiveWrappers) {
if (shouldThrowNpeOnExplicitEqualsForBoxedNull) {
Type wrapperType = AsmUtil.asmTypeByFqNameWithoutInnerClasses(JvmPrimitiveType.get(type).getWrapperFqName());
equalsMethod = new ConsistentEquals(wrapperType);
equalsMethod = new EqualsThrowingNpeForNullReceiver(wrapperType);
}
else {
equalsMethod = EQUALS;
@@ -142,7 +142,11 @@ class GenerationState @JvmOverloads constructor(
this.bindingContext, classBuilderMode, IncompatibleClassTrackerImpl(extraJvmDiagnosticsTrace),
this.moduleName, isJvm8Target, isJvm8TargetWithDefaults
)
val intrinsics: IntrinsicMethods = IntrinsicMethods(target, languageVersionSettings.supportsFeature(LanguageFeature.ConsistentExplicitEqualsForPrimitiveWrappers))
val intrinsics: IntrinsicMethods = run {
val shouldUseConsistentEquals = languageVersionSettings.supportsFeature(LanguageFeature.ThrowNpeOnExplicitEqualsForBoxedNull) &&
!configuration.getBoolean(JVMConfigurationKeys.NO_EXCEPTION_ON_EXPLICIT_EQUALS_FOR_BOXED_NULL)
IntrinsicMethods(target, shouldUseConsistentEquals)
}
val samWrapperClasses: SamWrapperClasses = SamWrapperClasses(this)
val inlineCycleReporter: InlineCycleReporter = InlineCycleReporter(diagnostics)
val mappingsClassesForWhenByEnum: MappingsClassesForWhenByEnum = MappingsClassesForWhenByEnum(this)