@@ -2,7 +2,7 @@ package dotty.tools
2
2
package dotc
3
3
package core
4
4
5
- import Contexts ._ , Types ._ , Symbols ._ , Names ._ , Flags ._
5
+ import Contexts ._ , Types ._ , Symbols ._ , Names ._ , NameKinds . * , Flags ._
6
6
import SymDenotations ._
7
7
import util .Spans ._
8
8
import util .Stats
@@ -839,40 +839,59 @@ object TypeOps:
839
839
}
840
840
}
841
841
842
+ object TraverseTp2 extends TypeTraverser :
843
+ val singletons = new mutable.ListBuffer [SingletonType ]
844
+ val gadtSyms = new mutable.ListBuffer [Symbol ]
845
+ def traverse (tp : Type ) =
846
+ val tpd = tp.dealias
847
+ if tpd ne tp then traverse(tpd)
848
+ else tp match
849
+ case tp : SingletonType if ! singletons.contains(tp)=>
850
+ singletons += tp
851
+ traverseChildren(tp)
852
+ case tp : TypeRef if tp.symbol.isAbstractOrParamType =>
853
+ gadtSyms += tp.symbol
854
+ traverseChildren(tp)
855
+ case _ =>
856
+ traverseChildren(tp)
857
+ TraverseTp2 .traverse(tp2)
858
+ val singletons = TraverseTp2 .singletons.toList
859
+ val gadtSyms = TraverseTp2 .gadtSyms.toList
860
+
842
861
// Prefix inference, replace `p.C.this.Child` with `X.Child` where `X <: p.C`
843
862
// Note: we need to strip ThisType in `p` recursively.
844
863
//
845
864
// See tests/patmat/i3938.scala
846
865
class InferPrefixMap extends TypeMap {
847
866
var prefixTVar : Type | Null = null
848
867
def apply (tp : Type ): Type = tp match {
849
- case ThisType (tref : TypeRef ) if ! tref.symbol.isStaticOwner =>
868
+ case ThisType (tref) if ! tref.symbol.isStaticOwner =>
850
869
val symbol = tref.symbol
851
- if (symbol.is(Module ))
870
+ val singletonIx = singletons.indexWhere(_.classSymbol == symbol)
871
+ if singletonIx >= 0 then
872
+ prefixTVar = singletons(singletonIx)
873
+ prefixTVar.uncheckedNN
874
+ else if symbol.is(Module ) then
852
875
TermRef (this (tref.prefix), symbol.sourceModule)
853
876
else if (prefixTVar != null )
854
877
this (tref)
855
878
else {
856
879
prefixTVar = WildcardType // prevent recursive call from assigning it
857
- val tvars = tref.typeParams.map { tparam => newTypeVar(tparam.paramInfo.bounds) }
880
+ val tvars = tref.typeParams.map { tparam => newTypeVar(tparam.paramInfo.bounds, DepParamName .fresh(tparam.paramName) ) }
858
881
val tref2 = this (tref.applyIfParameterized(tvars))
859
- prefixTVar = newTypeVar(TypeBounds .upper(tref2))
882
+ prefixTVar = newTypeVar(TypeBounds .upper(tref2), DepParamName .fresh(tref.name) )
860
883
prefixTVar.uncheckedNN
861
884
}
862
885
case tp => mapOver(tp)
863
886
}
864
887
}
865
888
866
889
val inferThisMap = new InferPrefixMap
867
- val tvars = tp1.typeParams.map { tparam => newTypeVar(tparam.paramInfo.bounds) }
890
+ val tvars = tp1.typeParams.map { tparam => newTypeVar(tparam.paramInfo.bounds, DepParamName .fresh(tparam.paramName) ) }
868
891
val protoTp1 = inferThisMap.apply(tp1).appliedTo(tvars)
869
892
870
- val getAbstractSymbols = new TypeAccumulator [List [Symbol ]]:
871
- def apply (xs : List [Symbol ], tp : Type ) = tp.dealias match
872
- case tp : TypeRef if tp.symbol.exists && ! tp.symbol.isClass => foldOver(tp.symbol :: xs, tp)
873
- case tp => foldOver(xs, tp)
874
- val syms2 = getAbstractSymbols(Nil , tp2).reverse
875
- if syms2.nonEmpty then ctx.gadtState.addToConstraint(syms2)
893
+ if gadtSyms.nonEmpty then
894
+ ctx.gadtState.addToConstraint(gadtSyms)
876
895
877
896
// If parent contains a reference to an abstract type, then we should
878
897
// refine subtype checking to eliminate abstract types according to
0 commit comments