File tree Expand file tree Collapse file tree 2 files changed +33
-2
lines changed
compiler/src/dotty/tools/dotc/core Expand file tree Collapse file tree 2 files changed +33
-2
lines changed Original file line number Diff line number Diff line change @@ -805,9 +805,13 @@ object TypeOps:
805
805
prefixTVar.uncheckedNN
806
806
case ThisType (tref) if ! tref.symbol.isStaticOwner =>
807
807
val symbol = tref.symbol
808
+ val compatibleSingleton = singletons.valuesIterator.find(_.underlying.derivesFrom(symbol))
808
809
if singletons.contains(symbol) then
809
810
prefixTVar = singletons(symbol) // e.g. tests/pos/i16785.scala, keep Outer.this
810
811
prefixTVar.uncheckedNN
812
+ else if compatibleSingleton.isDefined then
813
+ prefixTVar = compatibleSingleton.get
814
+ prefixTVar.uncheckedNN
811
815
else if symbol.is(Module ) then
812
816
TermRef (this (tref.prefix), symbol.sourceModule)
813
817
else if (prefixTVar != null )
@@ -905,10 +909,11 @@ object TypeOps:
905
909
}
906
910
907
911
val inferThisMap = new InferPrefixMap
908
- val tvars = tp1.etaExpand match
912
+ val prefixInferredTp = inferThisMap(tp1)
913
+ val tvars = prefixInferredTp.etaExpand match
909
914
case eta : TypeLambda => constrained(eta)
910
915
case _ => Nil
911
- val protoTp1 = inferThisMap.apply(tp1) .appliedTo(tvars)
916
+ val protoTp1 = prefixInferredTp .appliedTo(tvars)
912
917
913
918
if gadtSyms.nonEmpty then
914
919
ctx.gadtState.addToConstraint(gadtSyms)
Original file line number Diff line number Diff line change
1
+ class Module {
2
+ type BarTy
3
+ sealed trait Adt [A ]
4
+ case class Foo () extends Adt [String ]
5
+ case class Bar [A <: BarTy ](x : BarTy ) extends Adt [A ]
6
+ }
7
+
8
+ object Basic extends Module {
9
+ type BarTy = String
10
+ }
11
+
12
+ def test (a : Basic .Adt [String ]) = {
13
+ a match { // warn: match may not be exhaustive
14
+ case Basic .Foo () =>
15
+ }
16
+ }
17
+
18
+ object Basic2 extends Module {
19
+ type BarTy = Int
20
+ }
21
+
22
+ def test2 (a : Basic2 .Adt [String ]) = {
23
+ a match {
24
+ case Basic2 .Foo () =>
25
+ }
26
+ }
You can’t perform that action at this time.
0 commit comments