Skip to content

Commit 92b0bc2

Browse files
committed
Normalize TermRefs in QualifierComparer
1 parent 1ff0ca3 commit 92b0bc2

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

compiler/src/dotty/tools/dotc/qualified_types/QualifierComparer.scala

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ package dotty.tools.dotc.qualified_types
33
import scala.util.hashing.MurmurHash3 as hashing
44

55
import dotty.tools.dotc.ast.tpd.{closureDef, Apply, Block, DefDef, Ident, Literal, New, Select, Tree, TreeOps, TypeApply, Typed, TypeTree}
6-
import dotty.tools.dotc.core.Contexts.Context
6+
import dotty.tools.dotc.core.Contexts.{ctx, Context}
77
import dotty.tools.dotc.core.Decorators.i
88
import dotty.tools.dotc.core.Symbols.Symbol
9-
import dotty.tools.dotc.core.Types.{MethodType, TermRef, Type, TypeVar}
9+
import dotty.tools.dotc.core.Types.{MethodType, NamedType, TermRef, Type, TypeVar}
1010
import dotty.tools.dotc.core.Symbols.defn
1111

1212
import dotty.tools.dotc.reporting.trace
1313
import dotty.tools.dotc.config.Printers
1414

1515
private abstract class QualifierComparer:
16-
private def typeIso(tp1: Type, tp2: Type) =
16+
protected def typeIso(tp1: Type, tp2: Type) =
1717
val tp1stripped = stripPermanentTypeVar(tp1)
1818
val tp2stripped = stripPermanentTypeVar(tp2)
1919
tp1stripped.equals(tp2stripped)
@@ -91,6 +91,16 @@ private[qualified_types] object QualifierStructuralComparer extends QualifierCom
9191
override def hashCode: Int = hash(tree)
9292

9393
private[qualified_types] final class QualifierAlphaComparer(using Context) extends QualifierComparer:
94+
override protected def typeIso(tp1: Type, tp2: Type): Boolean =
95+
def normalizeType(tp: Type): Type =
96+
tp match
97+
case tp: TypeVar if tp.isPermanentlyInstantiated => tp.permanentInst
98+
case tp: NamedType =>
99+
if tp.symbol.isStatic then tp.symbol.termRef
100+
else normalizeType(tp.prefix).select(tp.symbol)
101+
case tp => tp
102+
super.typeIso(normalizeType(tp1), normalizeType(tp2))
103+
94104
override def iso(tree1: Tree, tree2: Tree): Boolean =
95105
trace(i"iso $tree1 ; $tree2"):
96106
(tree1, tree2) match
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
def tp[T](): Boolean = ???
2+
3+
class Outer:
4+
class Inner:
5+
class D
6+
summon[{v: Boolean with tp[Inner.this.D]()} =:= {v: Boolean with tp[D]()}]
7+
8+
object OuterO:
9+
object InnerO:
10+
class D
11+
summon[{v: Boolean with tp[InnerO.this.D]()} =:= {v: Boolean with tp[D]()}]
12+
summon[{v: Boolean with tp[InnerO.D]()} =:= {v: Boolean with tp[D]()}]
13+
summon[{v: Boolean with tp[OuterO.InnerO.D]()} =:= {v: Boolean with tp[D]()}]

tests/pos-custom-args/qualified-types/subtyping_unfolding.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ def test: Unit =
2424

2525
summon[{v: Int with v == id(x)} <:< {v: Int with v == id(x2)}]
2626
summon[{v: Int with v == id(x2)} <:< {v: Int with v == id(x)}]
27-
//summon[{v: Int with v == id(y)} <:< {v: Int with v == id(x + 1)}] // TODO(mbovel): needs normaliazion of type hashes
28-
//summon[{v: Int with v == id(x + 1)} <:< {v: Int with v == id(y)}] // TODO(mbovel): needs normaliazion of type hashes
27+
summon[{v: Int with v == id(y)} <:< {v: Int with v == id(x + 1)}]
28+
summon[{v: Int with v == id(x + 1)} <:< {v: Int with v == id(y)}]
2929

3030
summon[{v: Int with v == y + 2} <:< {v: Int with v == x + 1 + 2}]
3131
summon[{v: Int with v == x + 1 + 2} <:< {v: Int with v == y + 2}]
@@ -45,8 +45,8 @@ def test: Unit =
4545

4646
summon[{v: Int with v == id(x)} <:< {v: Int with v == id(x2)}]
4747
summon[{v: Int with v == id(x2)} <:< {v: Int with v == id(x)}]
48-
//summon[{v: Int with v == id(y)} <:< {v: Int with v == id(x + 1)}] // TODO(mbovel): needs normaliazion of type hashes
49-
//summon[{v: Int with v == id(x + 1)} <:< {v: Int with v == id(y)}] // TODO(mbovel): needs normaliazion of type hashes
48+
summon[{v: Int with v == id(y)} <:< {v: Int with v == id(x + 1)}]
49+
summon[{v: Int with v == id(x + 1)} <:< {v: Int with v == id(y)}]
5050

5151
summon[{v: Int with v == y + 2} <:< {v: Int with v == x + 1 + 2}]
5252
summon[{v: Int with v == x + 1 + 2} <:< {v: Int with v == y + 2}]

0 commit comments

Comments
 (0)