Skip to content

Commit a1930c4

Browse files
committed
DropSkolemMap: simplify logic
No need to save the value of `refersToSkolem`: if it's true before we enter `NamedType` it will be true after and `dropSkolem` will return `NoType`. The previous logic could still be useful if we want to give more easily actionable error messages in the future by only keeping in the type the skolems we couldn't remove.
1 parent 61b5a7b commit a1930c4

File tree

1 file changed

+19
-22
lines changed

1 file changed

+19
-22
lines changed

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

+19-22
Original file line numberDiff line numberDiff line change
@@ -3531,33 +3531,30 @@ class MatchReducer(initctx: Context) extends TypeComparer(initctx) {
35313531
class DropSkolemMap(skolem: SkolemType) extends TypeMap:
35323532
var refersToSkolem = false
35333533
def apply(tp: Type): Type =
3534+
if refersToSkolem then
3535+
return tp
35343536
tp match
35353537
case `skolem` =>
35363538
refersToSkolem = true
35373539
tp
35383540
case tp: NamedType if betterMatchTypeExtractorsEnabled =>
3539-
var savedRefersToSkolem = refersToSkolem
3540-
refersToSkolem = false
3541-
try
3542-
val pre1 = apply(tp.prefix)
3543-
if refersToSkolem then
3544-
tp match
3545-
case tp: TermRef => tp.info.widenExpr.dealias match
3546-
case info: SingletonType =>
3547-
refersToSkolem = false
3548-
apply(info)
3549-
case _ =>
3550-
tp.derivedSelect(pre1)
3551-
case tp: TypeRef => tp.info match
3552-
case info: AliasingBounds =>
3553-
refersToSkolem = false
3554-
apply(info.alias)
3555-
case _ =>
3556-
tp.derivedSelect(pre1)
3557-
else
3558-
tp.derivedSelect(pre1)
3559-
finally
3560-
refersToSkolem |= savedRefersToSkolem
3541+
val pre1 = apply(tp.prefix)
3542+
if refersToSkolem then
3543+
tp match
3544+
case tp: TermRef => tp.info.widenExpr.dealias match
3545+
case info: SingletonType =>
3546+
refersToSkolem = false
3547+
apply(info)
3548+
case _ =>
3549+
tp.derivedSelect(pre1)
3550+
case tp: TypeRef => tp.info match
3551+
case info: AliasingBounds =>
3552+
refersToSkolem = false
3553+
apply(info.alias)
3554+
case _ =>
3555+
tp.derivedSelect(pre1)
3556+
else
3557+
tp.derivedSelect(pre1)
35613558
case tp: LazyRef if betterMatchTypeExtractorsEnabled =>
35623559
// By default, TypeMap maps LazyRefs lazily. We need to
35633560
// force it for `refersToSkolem` to be correctly set.

0 commit comments

Comments
 (0)