Type intersection fix: T & (final A) is no more calculated as just A #KT-7801 Fixed
This commit is contained in:
@@ -78,21 +78,27 @@ public class TypeIntersector {
|
|||||||
outer:
|
outer:
|
||||||
for (KotlinType type : nullabilityStripped) {
|
for (KotlinType type : nullabilityStripped) {
|
||||||
if (!TypeUtils.canHaveSubtypes(typeChecker, type)) {
|
if (!TypeUtils.canHaveSubtypes(typeChecker, type)) {
|
||||||
|
boolean relativeToAll = true;
|
||||||
for (KotlinType other : nullabilityStripped) {
|
for (KotlinType other : nullabilityStripped) {
|
||||||
// It makes sense to check for subtyping (other <: type), despite that
|
// It makes sense to check for subtyping (other <: type), despite that
|
||||||
// type is not supposed to be open, for there're enums
|
// type is not supposed to be open, for there're enums
|
||||||
if (!TypeUnifier.mayBeEqual(type, other) && !typeChecker.isSubtypeOf(type, other) && !typeChecker.isSubtypeOf(other, type)) {
|
boolean mayBeEqual = TypeUnifier.mayBeEqual(type, other);
|
||||||
|
boolean relative = typeChecker.isSubtypeOf(type, other) || typeChecker.isSubtypeOf(other, type);
|
||||||
|
if (!mayBeEqual && !relative) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
else if (!relative) {
|
||||||
return TypeUtils.makeNullableAsSpecified(type, allNullable);
|
// To build T & (final A), instead of returning just A as intersection
|
||||||
}
|
relativeToAll = false;
|
||||||
else {
|
break;
|
||||||
for (KotlinType other : nullabilityStripped) {
|
|
||||||
if (!type.equals(other) && typeChecker.isSubtypeOf(other, type)) {
|
|
||||||
continue outer;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (relativeToAll) return TypeUtils.makeNullableAsSpecified(type, allNullable);
|
||||||
|
}
|
||||||
|
for (KotlinType other : nullabilityStripped) {
|
||||||
|
if (!type.equals(other) && typeChecker.isSubtypeOf(other, type)) {
|
||||||
|
continue outer;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't add type if it is already present, to avoid trivial type intersections in result
|
// Don't add type if it is already present, to avoid trivial type intersections in result
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ fun <T : CharSequence?> foo(x: T) {
|
|||||||
<!DEBUG_INFO_SMARTCAST!>x<!>.length
|
<!DEBUG_INFO_SMARTCAST!>x<!>.length
|
||||||
x<!UNNECESSARY_SAFE_CALL!>?.<!>length
|
x<!UNNECESSARY_SAFE_CALL!>?.<!>length
|
||||||
|
|
||||||
<!DEBUG_INFO_SMARTCAST!>x<!>.bar1()
|
x.bar1()
|
||||||
x.bar2()
|
x.bar2()
|
||||||
<!DEBUG_INFO_SMARTCAST!>x<!>.bar3()
|
<!DEBUG_INFO_SMARTCAST!>x<!>.bar3()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user