Skip to content

Commit b4376a1

Browse files
committed
Simplify isUnsafelyConvertible
1 parent e80c239 commit b4376a1

File tree

2 files changed

+6
-14
lines changed

2 files changed

+6
-14
lines changed

compiler/src/dotty/tools/dotc/core/NullOpsDecorator.scala

+5-13
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ object NullOpsDecorator {
5858
stripped ne self
5959
}
6060

61-
/** Can the type has null value after erasure?
62-
*/
61+
/** Can the type has null value after erasure? */
62+
// TODO
6363
def isNullableAfterErasure(using Context): Boolean = self match {
6464
case tp: ClassInfo => tp.cls.isNullableClassAfterErasure
6565
case tp: TypeProxy => tp.underlying.isNullableAfterErasure
@@ -74,17 +74,9 @@ object NullOpsDecorator {
7474
def isUnsafelyNulltoAnyRef(pt: Type)(using Context): Boolean =
7575
self.isNullType && pt.isNullableAfterErasure
7676

77-
def isUnsafeSubtype(pt: Type, relaxedSubtype: Boolean = false)(using Context): Boolean =
78-
val selfs = self.stripAllNulls
79-
val pts = pt.stripAllNulls
80-
if relaxedSubtype then
81-
selfs relaxed_<:< pts
82-
else
83-
selfs <:< pts
84-
85-
/** Can we convert a tree with type `self` to type `pt` unsafely.
86-
*/
77+
/** Can we convert a tree with type `self` to type `pt` unsafely. */
8778
def isUnsafelyConvertible(pt: Type, relaxedSubtype: Boolean = false)(using Context): Boolean =
88-
self.isUnsafelyNulltoAnyRef(pt) || self.isUnsafeSubtype(pt, relaxedSubtype)
79+
self.isUnsafelyNulltoAnyRef(pt)
80+
|| TypeComparer.topLevelSubTypeIgnoringNulls(self, pt)
8981
}
9082
}

compiler/src/dotty/tools/dotc/typer/Implicits.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ object Implicits:
135135
if (approx) formal = wildApprox(formal)
136136
explore((argType relaxed_<:< formal.widenExpr) ||
137137
Nullables.convertUnsafeNulls &&
138-
argType.isUnsafeSubtype(formal.widenExpr, true))
138+
argType.isUnsafelyConvertible(formal.widenExpr))
139139
})
140140
Candidate.Conversion
141141
else

0 commit comments

Comments
 (0)