Skip to content

Commit cfa4378

Browse files
committed
Suppress warning for known issue of exporting Polymorphic type
1 parent a276ec0 commit cfa4378

File tree

1 file changed

+39
-18
lines changed

1 file changed

+39
-18
lines changed

compiler/src/dotty/tools/dotc/semanticdb/TypeOps.scala

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,37 @@ class TypeOps:
2323
given typeOps: TypeOps = this
2424

2525
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] =
2727
val sym = symtab.get(key)
2828
if sym.isEmpty then
29-
symbolNotFound(key._1, key._2)
29+
symbolNotFound(key._1, key._2, parent)
3030
sym
3131

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+
)
3657

3758
extension (tpe: Type)
3859
def toSemanticSig(using LinkMode, Context, SemanticSymbolBuilder)(sym: Symbol): s.Signature =
@@ -123,12 +144,12 @@ class TypeOps:
123144
): (Type, List[List[Symbol]], List[Symbol]) = t match {
124145
case mt: MethodType =>
125146
val syms = mt.paramNames.flatMap { paramName =>
126-
paramRefSymtab.getOrErr((mt, paramName))
147+
paramRefSymtab.getOrErr((mt, paramName), sym)
127148
}
128149
flatten(mt.resType, paramss :+ syms, tparams)
129150
case pt: PolyType =>
130151
val syms = pt.paramNames.flatMap { paramName =>
131-
paramRefSymtab.getOrErr((pt, paramName))
152+
paramRefSymtab.getOrErr((pt, paramName), sym)
132153
}
133154
// there shouldn't multiple type params
134155
flatten(pt.resType, paramss, syms)
@@ -142,13 +163,13 @@ class TypeOps:
142163
s.MethodSignature(
143164
stparams,
144165
sparamss,
145-
resType.toSemanticType
166+
resType.toSemanticType(sym)
146167
)
147168

148169
case cls: ClassInfo =>
149170
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)
152173
val decls = cls.decls.toList.sscopeOpt
153174
s.ClassSignature(stparams, sparents, sself, decls)
154175

@@ -162,27 +183,27 @@ class TypeOps:
162183
val wildcardSym = newSymbol(NoSymbol, tpnme.WILDCARD, Flags.EmptyFlags, bounds)
163184
Some(wildcardSym)
164185
else
165-
paramRefSymtab.getOrErr((lambda, paramName))
186+
paramRefSymtab.getOrErr((lambda, paramName), sym)
166187
}
167188
(lambda.resType, paramSyms)
168189
case _ => (tpe, Nil)
169190
}
170191
val (loRes, loParams) = tparams(lo)
171192
val (hiRes, hiParams) = tparams(hi)
172193
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)
175196
val stparams = params.sscopeOpt
176197
s.TypeSignature(stparams, slo, shi)
177198

178199
case other =>
179200
s.ValueSignature(
180-
other.toSemanticType
201+
other.toSemanticType(sym)
181202
)
182203
}
183204
loop(tpe)
184205

185-
private def toSemanticType(using LinkMode, SemanticSymbolBuilder, Context): s.Type =
206+
private def toSemanticType(sym: Symbol)(using LinkMode, SemanticSymbolBuilder, Context): s.Type =
186207
import ConstantOps._
187208
def loop(tpe: Type): s.Type = tpe match {
188209
case ExprType(tpe) =>
@@ -201,7 +222,7 @@ class TypeOps:
201222

202223
case tref: ParamRef =>
203224
val key = (tref.binder, tref.paramName)
204-
paramRefSymtab.getOrErr(key) match {
225+
paramRefSymtab.getOrErr(key, sym) match {
205226
case Some(ref) =>
206227
val ssym = ref.symbolName
207228
tref match {
@@ -259,7 +280,7 @@ class TypeOps:
259280
val stpe = s.IntersectionType(flattenParent(parent))
260281

261282
val decls = refinedInfos.flatMap { (name, _) =>
262-
refinementSymtab.getOrErr((rt, name))
283+
refinementSymtab.getOrErr((rt, name), sym)
263284
}
264285
val sdecls = decls.sscopeOpt(using LinkMode.HardlinkChildren)
265286
s.StructuralType(stpe, sdecls)

0 commit comments

Comments
 (0)