@@ -14,7 +14,7 @@ import ast.tpd._
1414import collection .mutable
1515
1616import dotty .tools .dotc .{semanticdb => s }
17- import Scala3 .{SemanticSymbol , WildcardTypeSymbol }
17+ import Scala3 .{SemanticSymbol , WildcardTypeSymbol , TypeParamRefSymbol }
1818
1919class TypeOps :
2020 import SymbolScopeOps ._
@@ -24,31 +24,31 @@ class TypeOps:
2424 given typeOps : TypeOps = this
2525
2626 extension [T <: LambdaType | RefinedType ](symtab : mutable.Map [(T , Name ), Symbol ])
27- private def getOrErr (binder : T , name : Name , parent : Symbol )(using Context ): Option [Symbol ] =
27+ private def lookupOrErr (
28+ binder : T ,
29+ name : Name ,
30+ parent : Symbol ,
31+ )(using Context ): Option [Symbol ] =
2832 // In case refinement or type param cannot be accessed from traverser and
2933 // no symbols are registered to the symbol table, fall back to Type.member
30- val sym = symtab.getOrElse(
31- (binder, name),
32- binder.member(name).symbol
33- )
34+ val sym = symtab.lookup(binder, name, parent)
3435 if sym.exists then
3536 Some (sym)
3637 else
37- binder match {
38- // In case symtab and Type.member failed to find the symbol
39- // e.g. `class HKClass[F <: [T] =>> [U] =>> (U, T)]`
40- // and if the binder is HKTypeLambda, fallback to create fake symbol
41- case lam : HKTypeLambda =>
42- lam.paramNames.zip(lam.paramInfos).find(t => t._1 == name) match
43- case Some (info) =>
44- Some (newSymbol(parent, name, Flags .TypeParam , info._2))
45- case None =>
46- symbolNotFound(binder, name, parent)
47- None
48- case _ =>
49- symbolNotFound(binder, name, parent)
50- None
51- }
38+ symbolNotFound(binder, name, parent)
39+ None
40+
41+ private def lookup (
42+ binder : T ,
43+ name : Name ,
44+ parent : Symbol ,
45+ )(using Context ): Symbol =
46+ // In case refinement or type param cannot be accessed from traverser and
47+ // no symbols are registered to the symbol table, fall back to Type.member
48+ symtab.getOrElse(
49+ (binder, name),
50+ binder.member(name).symbol
51+ )
5252
5353 private def symbolNotFound (binder : Type , name : Name , parent : Symbol )(using ctx : Context ): Unit =
5454 warn(s " Ignoring ${name} of symbol ${parent}, type ${binder}" )
@@ -148,12 +148,12 @@ class TypeOps:
148148 ): (Type , List [List [Symbol ]], List [Symbol ]) = t match {
149149 case mt : MethodType =>
150150 val syms = mt.paramNames.flatMap { paramName =>
151- paramRefSymtab.getOrErr (mt, paramName, sym)
151+ paramRefSymtab.lookupOrErr (mt, paramName, sym)
152152 }
153153 flatten(mt.resType, paramss :+ syms, tparams)
154154 case pt : PolyType =>
155155 val syms = pt.paramNames.flatMap { paramName =>
156- paramRefSymtab.getOrErr (pt, paramName, sym)
156+ paramRefSymtab.lookupOrErr (pt, paramName, sym)
157157 }
158158 flatten(pt.resType, paramss, tparams ++ syms)
159159 case other =>
@@ -185,7 +185,11 @@ class TypeOps:
185185 if paramName.isWildcard then
186186 Some (WildcardTypeSymbol (bounds))
187187 else
188- paramRefSymtab.getOrErr(lambda, paramName, sym)
188+ val found = paramRefSymtab.lookup(lambda, paramName, sym)
189+ if found.exists then
190+ Some (found)
191+ else
192+ Some (TypeParamRefSymbol (sym, paramName, bounds))
189193 }
190194 (lambda.resType, paramSyms)
191195 case _ => (tpe, Nil )
@@ -221,22 +225,38 @@ class TypeOps:
221225 val ssym = sym.symbolName
222226 s.SingleType (spre, ssym)
223227
224- case tref : ParamRef =>
225- paramRefSymtab.getOrErr(
228+ case ThisType (TypeRef (_, sym : Symbol )) =>
229+ s.ThisType (sym.symbolName)
230+
231+ case tref : TermParamRef =>
232+ paramRefSymtab.lookupOrErr(
226233 tref.binder, tref.paramName, sym
227- ) match {
234+ ) match
228235 case Some (ref) =>
229236 val ssym = ref.symbolName
230- tref match {
231- case _ : TypeParamRef => s.TypeRef (s.Type .Empty , ssym, Seq .empty)
232- case _ : TermParamRef => s.SingleType (s.Type .Empty , ssym)
233- }
237+ s.SingleType (s.Type .Empty , ssym)
234238 case None =>
235239 s.Type .Empty
236- }
237240
238- case ThisType (TypeRef (_, sym : Symbol )) =>
239- s.ThisType (sym.symbolName)
241+ case tref : TypeParamRef =>
242+ val found = paramRefSymtab.lookup(tref.binder, tref.paramName, sym)
243+ val tsym =
244+ if found.exists then
245+ Some (found)
246+ else
247+ tref.binder.typeParams.find(param => param.paramName == tref.paramName) match
248+ case Some (param) =>
249+ val info = param.paramInfo
250+ Some (TypeParamRefSymbol (sym, tref.paramName, info))
251+ case None =>
252+ symbolNotFound(tref.binder, tref.paramName, sym)
253+ None
254+ tsym match
255+ case Some (sym) =>
256+ val ssym = sym.symbolName
257+ s.TypeRef (s.Type .Empty , ssym, Seq .empty)
258+ case None =>
259+ s.Type .Empty
240260
241261 case SuperType (thistpe, supertpe) =>
242262 val spre = loop(thistpe.typeSymbol.info)
@@ -282,7 +302,7 @@ class TypeOps:
282302 val stpe = s.IntersectionType (flattenParent(parent))
283303
284304 val decls = refinedInfos.flatMap { (name, info) =>
285- refinementSymtab.getOrErr (rt, name, sym)
305+ refinementSymtab.lookupOrErr (rt, name, sym)
286306 }
287307 val sdecls = decls.sscopeOpt(using LinkMode .HardlinkChildren )
288308 s.StructuralType (stpe, sdecls)
0 commit comments