@@ -14,7 +14,7 @@ import ast.tpd._
14
14
import collection .mutable
15
15
16
16
import dotty .tools .dotc .{semanticdb => s }
17
- import Scala3 .{SemanticSymbol , WildcardTypeSymbol }
17
+ import Scala3 .{SemanticSymbol , WildcardTypeSymbol , TypeParamRefSymbol }
18
18
19
19
class TypeOps :
20
20
import SymbolScopeOps ._
@@ -24,31 +24,31 @@ class TypeOps:
24
24
given typeOps : TypeOps = this
25
25
26
26
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 ] =
28
32
// In case refinement or type param cannot be accessed from traverser and
29
33
// 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)
34
35
if sym.exists then
35
36
Some (sym)
36
37
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
+ )
52
52
53
53
private def symbolNotFound (binder : Type , name : Name , parent : Symbol )(using ctx : Context ): Unit =
54
54
warn(s " Ignoring ${name} of symbol ${parent}, type ${binder}" )
@@ -148,12 +148,12 @@ class TypeOps:
148
148
): (Type , List [List [Symbol ]], List [Symbol ]) = t match {
149
149
case mt : MethodType =>
150
150
val syms = mt.paramNames.flatMap { paramName =>
151
- paramRefSymtab.getOrErr (mt, paramName, sym)
151
+ paramRefSymtab.lookupOrErr (mt, paramName, sym)
152
152
}
153
153
flatten(mt.resType, paramss :+ syms, tparams)
154
154
case pt : PolyType =>
155
155
val syms = pt.paramNames.flatMap { paramName =>
156
- paramRefSymtab.getOrErr (pt, paramName, sym)
156
+ paramRefSymtab.lookupOrErr (pt, paramName, sym)
157
157
}
158
158
flatten(pt.resType, paramss, tparams ++ syms)
159
159
case other =>
@@ -185,7 +185,11 @@ class TypeOps:
185
185
if paramName.isWildcard then
186
186
Some (WildcardTypeSymbol (bounds))
187
187
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))
189
193
}
190
194
(lambda.resType, paramSyms)
191
195
case _ => (tpe, Nil )
@@ -221,22 +225,38 @@ class TypeOps:
221
225
val ssym = sym.symbolName
222
226
s.SingleType (spre, ssym)
223
227
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(
226
233
tref.binder, tref.paramName, sym
227
- ) match {
234
+ ) match
228
235
case Some (ref) =>
229
236
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)
234
238
case None =>
235
239
s.Type .Empty
236
- }
237
240
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
240
260
241
261
case SuperType (thistpe, supertpe) =>
242
262
val spre = loop(thistpe.typeSymbol.info)
@@ -282,7 +302,7 @@ class TypeOps:
282
302
val stpe = s.IntersectionType (flattenParent(parent))
283
303
284
304
val decls = refinedInfos.flatMap { (name, info) =>
285
- refinementSymtab.getOrErr (rt, name, sym)
305
+ refinementSymtab.lookupOrErr (rt, name, sym)
286
306
}
287
307
val sdecls = decls.sscopeOpt(using LinkMode .HardlinkChildren )
288
308
s.StructuralType (stpe, sdecls)
0 commit comments