@@ -34,7 +34,7 @@ class TypeOps:
3434 )(using Context ): Option [Symbol ] =
3535 symtab.get((binder, name))
3636
37- extension [T <: LambdaType ](symtab : mutable.Map [(T , Name ), Symbol ])
37+ extension [T <: LambdaType | RefinedType ](symtab : mutable.Map [(T , Name ), Symbol ])
3838 private def lookupOrErr (
3939 binder : T ,
4040 name : Name ,
@@ -228,26 +228,45 @@ class TypeOps:
228228 val stpe = loop(tpe)
229229 s.ByNameType (stpe)
230230
231- case TypeRef (pre , sym : Symbol ) =>
232- val spre = if tpe.hasTrivialPrefix then s. Type . Empty else loop(pre)
233- val ssym = sym.symbolName
234- s. TypeRef (spre, ssym, Seq .empty)
235-
231+ // sym of ` TypeRef(_ , sym)` may not be a Symbol but Name in some cases
232+ // e.g. in MatchType,
233+ // case x *: xs => x *: Concat[xs, Ys]
234+ // x and xs should have a typebounds <: Any, >: Nothing
235+ // but Any (and Nothing) are represented as TypeRef(<scala>, "Any" <- Name)
236236 case tr @ TypeRef (pre, _) if tr.symbol != NoSymbol =>
237237 val spre = if tpe.hasTrivialPrefix then s.Type .Empty else loop(pre)
238238 val ssym = tr.symbol.symbolName
239239 s.TypeRef (spre, ssym, Seq .empty)
240240
241- case TermRef (pre, sym : Symbol ) =>
241+ // when TypeRef refers the refinement of RefinedType e.g.
242+ // TypeRef for `foo.B` in `trait T[A] { val foo: { type B = A } = ???; def bar(b: foo.B) = () }` has NoSymbol
243+ case TypeRef (pre, name : Name ) =>
242244 val spre = if tpe.hasTrivialPrefix then s.Type .Empty else loop(pre)
243- val ssym = sym.symbolName
244- s.SingleType (spre, ssym)
245+ val maybeSym = pre.widen.dealias match
246+ case rt : RefinedType =>
247+ refinementSymtab.lookupOrErr(rt, name, rt.typeSymbol)
248+ case _ => None
249+ maybeSym match
250+ case Some (sym) =>
251+ s.TypeRef (spre, sym.symbolName, Seq .empty)
252+ case None => s.Type .Empty
245253
246254 case tr @ TermRef (pre, _) if tr.symbol != NoSymbol =>
247255 val spre = if (tpe.hasTrivialPrefix) s.Type .Empty else loop(pre)
248256 val ssym = tr.symbol.symbolName
249257 s.SingleType (spre, ssym)
250258
259+ case TermRef (pre, name : Name ) =>
260+ val spre = if tpe.hasTrivialPrefix then s.Type .Empty else loop(pre)
261+ val maybeSym = pre.widen.dealias match
262+ case rt : RefinedType =>
263+ refinementSymtab.lookupOrErr(rt, name, rt.typeSymbol)
264+ case _ => None
265+ maybeSym match
266+ case Some (sym) =>
267+ s.SingleType (spre, sym.symbolName)
268+ case None => s.Type .Empty
269+
251270 case ThisType (TypeRef (_, sym : Symbol )) =>
252271 s.ThisType (sym.symbolName)
253272
@@ -458,9 +477,6 @@ class TypeOps:
458477 private def hasTrivialPrefix (using Context ): Boolean =
459478 def checkTrivialPrefix (pre : Type , sym : Symbol )(using Context ): Boolean =
460479 pre =:= sym.owner.thisType
461- // Make sure `tr.symbol != NoSymbol` where `tr @ TypeRef(...)`, that happens
462- // when TypeRef refers the refinement of RefinedType e.g.
463- // TypeRef for `foo.B` in `trait T[A] { val foo: { type B = A } = ???; def bar(b: foo.B) = () }` has NoSymbol
464480 tpe match {
465481 case TypeRef (pre, sym : Symbol ) =>
466482 checkTrivialPrefix(pre, sym)
0 commit comments