@@ -23,37 +23,23 @@ class TypeOps:
23
23
given typeOps : TypeOps = this
24
24
25
25
extension [T <: Type ](symtab : mutable.Map [(T , Name ), Symbol ])
26
- private def getOrErr (key : (T , Name ), parent : Symbol )(using Context ): Option [Symbol ] =
27
- val sym = symtab.get(key)
28
- if sym.isEmpty then
29
- symbolNotFound(key._1, key._2, parent)
30
- sym
26
+ private def getOrErr (binder : T , name : Name , parent : Symbol )(using Context ): Option [Symbol ] =
27
+ // In case refinement or type param cannot be accessed from traverser and
28
+ // no symbols are registered to the symbol table, fall back to Type.member
29
+ val sym = symtab.getOrElse(
30
+ (binder, name),
31
+ binder.member(name).symbol
32
+ )
33
+ if sym.exists then
34
+ Some (sym)
35
+ else
36
+ symbolNotFound(binder, name, parent)
37
+ None
31
38
32
39
private def symbolNotFound (binder : Type , name : Name , parent : Symbol )(using ctx : Context ): Unit =
33
- // Known issue: for exports
34
- // ```
35
- // // in Codec.scala
36
- // trait Encoder[T] ...
37
- //
38
- // // in ExportCodec.scala
39
- // export Encoder
40
- // ```
41
- // There's type argument TypeParamRef("T") for Codec in `ExportCodec.scala` whose binder is
42
- //
43
- // HKTypeLambda(
44
- // List(T),
45
- // List(TypeBounds(...)),
46
- // AppliedType(
47
- // TypeRef(... trait Decoder),
48
- // List(TypeParamRef(T))
49
- // )
50
- // )
51
- // where this HKTypeLambda never appears in the source code of `ExportCodec.scala`
52
- val suppress = parent.is(Flags .Exported )
53
- if ! suppress then
54
- report.warning(
55
- s """ Internal error in extracting SemanticDB while compiling ${ctx.compilationUnit.source}: Ignoring ${name} of type ${binder}"""
56
- )
40
+ report.warning(
41
+ s """ Internal error in extracting SemanticDB while compiling ${ctx.compilationUnit.source}: Ignoring ${name} of type ${binder}"""
42
+ )
57
43
58
44
extension (tpe : Type )
59
45
def toSemanticSig (using LinkMode , Context , SemanticSymbolBuilder )(sym : Symbol ): s.Signature =
@@ -144,12 +130,12 @@ class TypeOps:
144
130
): (Type , List [List [Symbol ]], List [Symbol ]) = t match {
145
131
case mt : MethodType =>
146
132
val syms = mt.paramNames.flatMap { paramName =>
147
- paramRefSymtab.getOrErr(( mt, paramName) , sym)
133
+ paramRefSymtab.getOrErr(mt, paramName, sym)
148
134
}
149
135
flatten(mt.resType, paramss :+ syms, tparams)
150
136
case pt : PolyType =>
151
137
val syms = pt.paramNames.flatMap { paramName =>
152
- paramRefSymtab.getOrErr(( pt, paramName) , sym)
138
+ paramRefSymtab.getOrErr(pt, paramName, sym)
153
139
}
154
140
// there shouldn't multiple type params
155
141
flatten(pt.resType, paramss, tparams ++ syms)
@@ -183,7 +169,7 @@ class TypeOps:
183
169
val wildcardSym = newSymbol(NoSymbol , tpnme.WILDCARD , Flags .EmptyFlags , bounds)
184
170
Some (wildcardSym)
185
171
else
186
- paramRefSymtab.getOrErr(( lambda, paramName) , sym)
172
+ paramRefSymtab.getOrErr(lambda, paramName, sym)
187
173
}
188
174
(lambda.resType, paramSyms)
189
175
case _ => (tpe, Nil )
@@ -221,15 +207,16 @@ class TypeOps:
221
207
s.SingleType (spre, ssym)
222
208
223
209
case tref : ParamRef =>
224
- val key = (tref.binder, tref.paramName)
225
- paramRefSymtab.getOrErr(key, sym) match {
210
+ paramRefSymtab.getOrErr(
211
+ tref.binder, tref.paramName, sym
212
+ ) match {
226
213
case Some (ref) =>
227
214
val ssym = ref.symbolName
228
215
tref match {
229
216
case _ : TypeParamRef => s.TypeRef (s.Type .Empty , ssym, Seq .empty)
230
217
case _ : TermParamRef => s.SingleType (s.Type .Empty , ssym)
231
218
}
232
- case None => // shouldn't happen
219
+ case None =>
233
220
s.Type .Empty
234
221
}
235
222
@@ -279,17 +266,8 @@ class TypeOps:
279
266
val (parent, refinedInfos) = flatten(rt, List .empty)
280
267
val stpe = s.IntersectionType (flattenParent(parent))
281
268
282
- val decls = refinedInfos.map { (name, info) =>
283
- // In case refinement cannot be accessed from traverser and
284
- // no symbols are registered to the symtab
285
- // fall back to Type.member
286
- val decl = refinementSymtab.getOrElse(
287
- (rt, name),
288
- rt.member(name).symbol
289
- )
290
- if decl == NoSymbol then
291
- symbolNotFound(rt, name, sym)
292
- decl
269
+ val decls = refinedInfos.flatMap { (name, info) =>
270
+ refinementSymtab.getOrErr(rt, name, sym)
293
271
}
294
272
val sdecls = decls.sscopeOpt(using LinkMode .HardlinkChildren )
295
273
s.StructuralType (stpe, sdecls)
0 commit comments