File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed
compiler/src/dotty/tools/dotc/typer Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -831,11 +831,13 @@ trait Implicits { self: Typer =>
831831 (other ne NoType ) && ! other.derivesFrom(defn.AnyValClass )
832832 }
833833
834+ // Map all non-opaque abstract types to their upper bound.
835+ // This is done to check whether such types might plausibly be comparable to each other.
834836 val lift = new TypeMap {
835837 def apply (t : Type ): Type = t match {
836838 case t : TypeRef =>
837839 t.info match {
838- case TypeBounds (lo, hi) if lo ne hi => apply(hi)
840+ case TypeBounds (lo, hi) if lo.ne(hi) && ! t.symbol.is( Opaque ) => apply(hi)
839841 case _ => t
840842 }
841843 case t : RefinedType =>
Original file line number Diff line number Diff line change 1+ import language .strictEquality
2+
3+ object O {
4+
5+ opaque type Meters = Double
6+ object Meters {
7+ def apply (d : Double ): Meters = d
8+ val m : Meters = 1.0
9+ assert(m == 1.0 ) // OK
10+ }
11+ implicit def eqM : Eq [Meters , Meters ] = Eq
12+
13+ opaque type Feet = Double
14+ object Feet { def apply (d : Double ): Feet = d }
15+ implicit def eqF : Eq [Feet , Feet ] = Eq
16+
17+ def main (args : Array [String ]): Unit = {
18+ println(Feet (3 ) == Meters (3 )) // error: cannot compare
19+ println(Feet (3 ) == 3.0 ) // error: cannot compare
20+ }
21+ }
You can’t perform that action at this time.
0 commit comments