Skip to content

Commit

Permalink
DropSkolemMap: simplify logic
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
smarter committed May 7, 2024
1 parent febb69c commit 19f145c
Showing 1 changed file with 19 additions and 22 deletions.
41 changes: 19 additions & 22 deletions compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3531,33 +3531,30 @@ class MatchReducer(initctx: Context) extends TypeComparer(initctx) {
class DropSkolemMap(skolem: SkolemType) extends TypeMap:
var refersToSkolem = false
def apply(tp: Type): Type =
if refersToSkolem then
return tp
tp match
case `skolem` =>
refersToSkolem = true
tp
case tp: NamedType if betterMatchTypeExtractorsEnabled =>
var savedRefersToSkolem = refersToSkolem
refersToSkolem = false
try
val pre1 = apply(tp.prefix)
if refersToSkolem then
tp match
case tp: TermRef => tp.info.widenExpr.dealias match
case info: SingletonType =>
refersToSkolem = false
apply(info)
case _ =>
tp.derivedSelect(pre1)
case tp: TypeRef => tp.info match
case info: AliasingBounds =>
refersToSkolem = false
apply(info.alias)
case _ =>
tp.derivedSelect(pre1)
else
tp.derivedSelect(pre1)
finally
refersToSkolem |= savedRefersToSkolem
val pre1 = apply(tp.prefix)
if refersToSkolem then
tp match
case tp: TermRef => tp.info.widenExpr.dealias match
case info: SingletonType =>
refersToSkolem = false
apply(info)
case _ =>
tp.derivedSelect(pre1)
case tp: TypeRef => tp.info match
case info: AliasingBounds =>
refersToSkolem = false
apply(info.alias)
case _ =>
tp.derivedSelect(pre1)
else
tp.derivedSelect(pre1)
case tp: LazyRef if betterMatchTypeExtractorsEnabled =>
// By default, TypeMap maps LazyRefs lazily. We need to
// force it for `refersToSkolem` to be correctly set.
Expand Down

0 comments on commit 19f145c

Please sign in to comment.