File tree 2 files changed +19
-1
lines changed
compiler/src/dotty/tools/dotc/typer 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -831,11 +831,13 @@ trait Implicits { self: Typer =>
831
831
(other ne NoType ) && ! other.derivesFrom(defn.AnyValClass )
832
832
}
833
833
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.
834
836
val lift = new TypeMap {
835
837
def apply (t : Type ): Type = t match {
836
838
case t : TypeRef =>
837
839
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)
839
841
case _ => t
840
842
}
841
843
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 { def apply (d : Double ): Meters = d }
7
+ implicit def eqM : Eq [Meters , Meters ] = Eq
8
+
9
+ opaque type Feet = Double
10
+ object Feet { def apply (d : Double ): Feet = d }
11
+ implicit def eqF : Eq [Feet , Feet ] = Eq
12
+
13
+ def main (args : Array [String ]): Unit =
14
+ println(Feet (3 ) == Meters (3 )) // error: cannot compare
15
+
16
+ }
You can’t perform that action at this time.
0 commit comments