@@ -23,16 +23,37 @@ 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 ))(using Context ): Option [Symbol ] =
26
+ private def getOrErr (key : (T , Name ), parent : Symbol )(using Context ): Option [Symbol ] =
27
27
val sym = symtab.get(key)
28
28
if sym.isEmpty then
29
- symbolNotFound(key._1, key._2)
29
+ symbolNotFound(key._1, key._2, parent )
30
30
sym
31
31
32
- private def symbolNotFound (binder : Type , name : Name )(using ctx : Context ): Unit =
33
- report.warning(
34
- s """ Internal error in extracting SemanticDB while compiling ${ctx.compilationUnit.source}: Ignoring ${name} of type ${binder}"""
35
- )
32
+ 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
+ )
36
57
37
58
extension (tpe : Type )
38
59
def toSemanticSig (using LinkMode , Context , SemanticSymbolBuilder )(sym : Symbol ): s.Signature =
@@ -123,12 +144,12 @@ class TypeOps:
123
144
): (Type , List [List [Symbol ]], List [Symbol ]) = t match {
124
145
case mt : MethodType =>
125
146
val syms = mt.paramNames.flatMap { paramName =>
126
- paramRefSymtab.getOrErr((mt, paramName))
147
+ paramRefSymtab.getOrErr((mt, paramName), sym )
127
148
}
128
149
flatten(mt.resType, paramss :+ syms, tparams)
129
150
case pt : PolyType =>
130
151
val syms = pt.paramNames.flatMap { paramName =>
131
- paramRefSymtab.getOrErr((pt, paramName))
152
+ paramRefSymtab.getOrErr((pt, paramName), sym )
132
153
}
133
154
// there shouldn't multiple type params
134
155
flatten(pt.resType, paramss, syms)
@@ -142,13 +163,13 @@ class TypeOps:
142
163
s.MethodSignature (
143
164
stparams,
144
165
sparamss,
145
- resType.toSemanticType
166
+ resType.toSemanticType(sym)
146
167
)
147
168
148
169
case cls : ClassInfo =>
149
170
val stparams = cls.cls.typeParams.sscopeOpt
150
- val sparents = cls.parents.map(_.toSemanticType)
151
- val sself = cls.selfType.toSemanticType
171
+ val sparents = cls.parents.map(_.toSemanticType(sym) )
172
+ val sself = cls.selfType.toSemanticType(sym)
152
173
val decls = cls.decls.toList.sscopeOpt
153
174
s.ClassSignature (stparams, sparents, sself, decls)
154
175
@@ -162,27 +183,27 @@ class TypeOps:
162
183
val wildcardSym = newSymbol(NoSymbol , tpnme.WILDCARD , Flags .EmptyFlags , bounds)
163
184
Some (wildcardSym)
164
185
else
165
- paramRefSymtab.getOrErr((lambda, paramName))
186
+ paramRefSymtab.getOrErr((lambda, paramName), sym )
166
187
}
167
188
(lambda.resType, paramSyms)
168
189
case _ => (tpe, Nil )
169
190
}
170
191
val (loRes, loParams) = tparams(lo)
171
192
val (hiRes, hiParams) = tparams(hi)
172
193
val params = (loParams ++ hiParams).distinctBy(_.name)
173
- val slo = loRes.toSemanticType
174
- val shi = hiRes.toSemanticType
194
+ val slo = loRes.toSemanticType(sym)
195
+ val shi = hiRes.toSemanticType(sym)
175
196
val stparams = params.sscopeOpt
176
197
s.TypeSignature (stparams, slo, shi)
177
198
178
199
case other =>
179
200
s.ValueSignature (
180
- other.toSemanticType
201
+ other.toSemanticType(sym)
181
202
)
182
203
}
183
204
loop(tpe)
184
205
185
- private def toSemanticType (using LinkMode , SemanticSymbolBuilder , Context ): s.Type =
206
+ private def toSemanticType (sym : Symbol )( using LinkMode , SemanticSymbolBuilder , Context ): s.Type =
186
207
import ConstantOps ._
187
208
def loop (tpe : Type ): s.Type = tpe match {
188
209
case ExprType (tpe) =>
@@ -201,7 +222,7 @@ class TypeOps:
201
222
202
223
case tref : ParamRef =>
203
224
val key = (tref.binder, tref.paramName)
204
- paramRefSymtab.getOrErr(key) match {
225
+ paramRefSymtab.getOrErr(key, sym ) match {
205
226
case Some (ref) =>
206
227
val ssym = ref.symbolName
207
228
tref match {
@@ -259,7 +280,7 @@ class TypeOps:
259
280
val stpe = s.IntersectionType (flattenParent(parent))
260
281
261
282
val decls = refinedInfos.flatMap { (name, _) =>
262
- refinementSymtab.getOrErr((rt, name))
283
+ refinementSymtab.getOrErr((rt, name), sym )
263
284
}
264
285
val sdecls = decls.sscopeOpt(using LinkMode .HardlinkChildren )
265
286
s.StructuralType (stpe, sdecls)
0 commit comments