@@ -34,7 +34,7 @@ class TypeOps:
34
34
)(using Context ): Option [Symbol ] =
35
35
symtab.get((binder, name))
36
36
37
- extension [T <: LambdaType ](symtab : mutable.Map [(T , Name ), Symbol ])
37
+ extension [T <: LambdaType | RefinedType ](symtab : mutable.Map [(T , Name ), Symbol ])
38
38
private def lookupOrErr (
39
39
binder : T ,
40
40
name : Name ,
@@ -228,26 +228,45 @@ class TypeOps:
228
228
val stpe = loop(tpe)
229
229
s.ByNameType (stpe)
230
230
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)
236
236
case tr @ TypeRef (pre, _) if tr.symbol != NoSymbol =>
237
237
val spre = if tpe.hasTrivialPrefix then s.Type .Empty else loop(pre)
238
238
val ssym = tr.symbol.symbolName
239
239
s.TypeRef (spre, ssym, Seq .empty)
240
240
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 ) =>
242
244
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
245
253
246
254
case tr @ TermRef (pre, _) if tr.symbol != NoSymbol =>
247
255
val spre = if (tpe.hasTrivialPrefix) s.Type .Empty else loop(pre)
248
256
val ssym = tr.symbol.symbolName
249
257
s.SingleType (spre, ssym)
250
258
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
+
251
270
case ThisType (TypeRef (_, sym : Symbol )) =>
252
271
s.ThisType (sym.symbolName)
253
272
@@ -458,9 +477,6 @@ class TypeOps:
458
477
private def hasTrivialPrefix (using Context ): Boolean =
459
478
def checkTrivialPrefix (pre : Type , sym : Symbol )(using Context ): Boolean =
460
479
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
464
480
tpe match {
465
481
case TypeRef (pre, sym : Symbol ) =>
466
482
checkTrivialPrefix(pre, sym)
0 commit comments