File tree 4 files changed +48
-1
lines changed
compiler/src/dotty/tools/dotc
4 files changed +48
-1
lines changed Original file line number Diff line number Diff line change @@ -1575,7 +1575,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
1575
1575
* Note: It would be legal to do the lifting also if M does not contain opaque types,
1576
1576
* but in this case the retries in tryLiftedToThis would be redundant.
1577
1577
*/
1578
- private def liftToThis (tp : Type ): Type = {
1578
+ def liftToThis (tp : Type ): Type = {
1579
1579
1580
1580
def findEnclosingThis (moduleClass : Symbol , from : Symbol ): Type =
1581
1581
if ((from.owner eq moduleClass) && from.isPackageObject && from.is(Opaque )) from.thisType
Original file line number Diff line number Diff line change @@ -712,6 +712,16 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
712
712
typedSelectWithAdapt(tree, pt, qual)
713
713
else EmptyTree
714
714
715
+ def tryLiftToThis () =
716
+ val wtp = qual.tpe.widen
717
+ val liftedTp = comparing(_.liftToThis(wtp))
718
+ if liftedTp ne wtp then
719
+ val qual1 = qual.cast(liftedTp)
720
+ val tree1 = cpy.Select (tree0)(qual1, selName)
721
+ val rawType1 = selectionType(tree1, qual1)
722
+ tryType(tree1, qual1, rawType1)
723
+ else EmptyTree
724
+
715
725
def trySmallGenericTuple (tree : untpd.Select , qual : Tree , withCast : Boolean ) =
716
726
if qual.tpe.isSmallGenericTuple then
717
727
if withCast then
@@ -761,6 +771,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
761
771
tryType(tree, qual, rawType)
762
772
.orElse(trySimplifyApply())
763
773
.orElse(tryInstantiateTypeVar())
774
+ .orElse(tryLiftToThis())
764
775
.orElse(trySmallGenericTuple(tree, qual, withCast = true ))
765
776
.orElse(tryExt(tree, qual))
766
777
.orElse(tryGadt(tree))
Original file line number Diff line number Diff line change
1
+ object o {
2
+ opaque type T = String
3
+
4
+ summon[o.T =:= T ] // OK
5
+ summon[o.T =:= String ] // OK
6
+
7
+ def test1 (t : T ): Int =
8
+ t.length // OK
9
+
10
+ def test2 (t : o.T ): Int =
11
+ t.length // Error: value length is not a member of Playground.o.T
12
+ }
Original file line number Diff line number Diff line change
1
+ object o { u =>
2
+ opaque type T = String
3
+
4
+ def st = summon[String =:= T ]
5
+ def su = summon[String =:= u.T ]
6
+ def so = summon[String =:= o.T ]
7
+
8
+ def ts = summon[T =:= String ]
9
+ def tu = summon[T =:= u.T ]
10
+ def to = summon[T =:= o.T ]
11
+
12
+ def us = summon[u.T =:= String ]
13
+ def ut = summon[u.T =:= T ]
14
+ def uo = summon[u.T =:= o.T ]
15
+
16
+ def os = summon[o.T =:= String ]
17
+ def ot = summon[o.T =:= T ]
18
+ def ou = summon[o.T =:= u.T ]
19
+
20
+ def ms (x : String ): Int = x.length // ok
21
+ def mt (x : T ): Int = x.length // ok
22
+ def mu (x : u.T ): Int = x.length // ok
23
+ def mo (x : o.T ): Int = x.length // was: error: value length is not a member of o.T
24
+ }
You can’t perform that action at this time.
0 commit comments