@@ -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 , TypeParamRefSymbol }
17
+ import Scala3 .{SemanticSymbol , WildcardTypeSymbol , TypeParamRefSymbol , TermParamRefSymbol , RefinementSymbol }
18
18
19
19
class TypeOps :
20
20
import SymbolScopeOps ._
@@ -24,31 +24,29 @@ 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 lookupOrErr (
27
+ private def lookup (
28
28
binder : T ,
29
29
name : Name ,
30
- parent : Symbol ,
31
30
)(using Context ): Option [Symbol ] =
32
- // In case refinement or type param cannot be accessed from traverser and
33
- // no symbols are registered to the symbol table, fall back to Type.member
34
- val sym = symtab.lookup(binder, name, parent)
35
- if sym.exists then
36
- Some (sym)
37
- else
38
- symbolNotFound(binder, name, parent)
39
- None
31
+ symtab.get((binder, name))
40
32
41
- private def lookup (
33
+ extension [T <: LambdaType ](symtab : mutable.Map [(T , Name ), Symbol ])
34
+ private def lookupOrErr (
42
35
binder : T ,
43
36
name : Name ,
44
37
parent : Symbol ,
45
- )(using Context ): Symbol =
38
+ )(using Context ): Option [ Symbol ] =
46
39
// In case refinement or type param cannot be accessed from traverser and
47
40
// 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
- )
41
+ symtab.lookup(binder, name) match
42
+ case found @ Some (_) => found
43
+ case None =>
44
+ val member = binder.member(name).symbol
45
+ if ! member.exists then
46
+ symbolNotFound(binder, name, parent)
47
+ None
48
+ else
49
+ Some (member)
52
50
53
51
private def symbolNotFound (binder : Type , name : Name , parent : Symbol )(using ctx : Context ): Unit =
54
52
warn(s " Ignoring ${name} of symbol ${parent}, type ${binder}" )
@@ -143,17 +141,21 @@ class TypeOps:
143
141
case mp : MethodOrPoly =>
144
142
def flatten (
145
143
t : Type ,
146
- paramss : List [List [Symbol ]],
147
- tparams : List [Symbol ]
148
- ): (Type , List [List [Symbol ]], List [Symbol ]) = t match {
144
+ paramss : List [List [SemanticSymbol ]],
145
+ tparams : List [SemanticSymbol ]
146
+ ): (Type , List [List [SemanticSymbol ]], List [SemanticSymbol ]) = t match {
149
147
case mt : MethodType =>
150
- val syms = mt.paramNames.flatMap { paramName =>
151
- paramRefSymtab.lookupOrErr(mt, paramName, sym)
148
+ val syms : List [SemanticSymbol ] = mt.paramNames.zip(mt.paramInfos).map { (name, info) =>
149
+ paramRefSymtab.lookup(mt, name).getOrElse(
150
+ TermParamRefSymbol (sym, name, info)
151
+ )
152
152
}
153
153
flatten(mt.resType, paramss :+ syms, tparams)
154
154
case pt : PolyType =>
155
- val syms = pt.paramNames.flatMap { paramName =>
156
- paramRefSymtab.lookupOrErr(pt, paramName, sym)
155
+ val syms : List [SemanticSymbol ] = pt.paramNames.zip(pt.paramInfos).map { (name, info) =>
156
+ paramRefSymtab.lookup(pt, name).getOrElse(
157
+ TypeParamRefSymbol (sym, name, info)
158
+ )
157
159
}
158
160
flatten(pt.resType, paramss, tparams ++ syms)
159
161
case other =>
@@ -180,16 +182,14 @@ class TypeOps:
180
182
// for `type X[T] = T` is equivalent to `[T] =>> T`
181
183
def tparams (tpe : Type ): (Type , List [SemanticSymbol ]) = tpe match {
182
184
case lambda : HKTypeLambda =>
183
- val paramSyms : List [SemanticSymbol ] = lambda.paramNames.zip(lambda.paramInfos).flatMap { (paramName, bounds) =>
185
+ val paramSyms : List [SemanticSymbol ] = lambda.paramNames.zip(lambda.paramInfos).map { (paramName, bounds) =>
184
186
// def x[T[_]] = ???
185
187
if paramName.isWildcard then
186
- Some ( WildcardTypeSymbol (sym, bounds) )
188
+ WildcardTypeSymbol (sym, bounds)
187
189
else
188
- val found = paramRefSymtab.lookup(lambda, paramName, sym)
189
- if found.exists then
190
- Some (found)
191
- else
192
- Some (TypeParamRefSymbol (sym, paramName, bounds))
190
+ paramRefSymtab.lookup(lambda, paramName).getOrElse(
191
+ TypeParamRefSymbol (sym, paramName, bounds)
192
+ )
193
193
}
194
194
(lambda.resType, paramSyms)
195
195
case _ => (tpe, Nil )
@@ -239,11 +239,9 @@ class TypeOps:
239
239
s.Type .Empty
240
240
241
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
242
+ val tsym = paramRefSymtab.lookup(tref.binder, tref.paramName) match
243
+ case found @ Some (sym) => found
244
+ case None =>
247
245
tref.binder.typeParams.find(param => param.paramName == tref.paramName) match
248
246
case Some (param) =>
249
247
val info = param.paramInfo
@@ -301,8 +299,10 @@ class TypeOps:
301
299
val (parent, refinedInfos) = flatten(rt, List .empty)
302
300
val stpe = s.IntersectionType (flattenParent(parent))
303
301
304
- val decls = refinedInfos.flatMap { (name, info) =>
305
- refinementSymtab.lookupOrErr(rt, name, sym)
302
+ val decls : List [SemanticSymbol ] = refinedInfos.map { (name, info) =>
303
+ refinementSymtab.lookup(rt, name).getOrElse(
304
+ RefinementSymbol (name, info)
305
+ )
306
306
}
307
307
val sdecls = decls.sscopeOpt(using LinkMode .HardlinkChildren )
308
308
s.StructuralType (stpe, sdecls)
@@ -331,6 +331,10 @@ class TypeOps:
331
331
)
332
332
s.AnnotatedType (sannots, sparent)
333
333
334
+ case AppliedType (tycon, args) if tycon == defn.RepeatedParamType && args.length == 1 =>
335
+ val stpe = loop(args(0 ))
336
+ s.RepeatedType (stpe)
337
+
334
338
case app @ AppliedType (tycon, args) =>
335
339
val targs = args.map { arg =>
336
340
arg match
0 commit comments