Skip to content

Commit 17c06dc

Browse files
committed
Warn if symbol lookup failed for paramRef and RefinedType
1 parent 2f13751 commit 17c06dc

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

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

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,19 @@ class TypeOps:
2121
private val paramRefSymtab = mutable.Map[(LambdaType, Name), Symbol]()
2222
private val refinementSymtab = mutable.Map[(RefinedType, Name), Symbol]()
2323
given typeOps: TypeOps = this
24+
25+
extension [T <: Type](symtab: mutable.Map[(T, Name), Symbol])
26+
private def getOrErr(key: (T, Name))(using Context): Option[Symbol] =
27+
val sym = symtab.get(key)
28+
if sym.isEmpty then
29+
symbolNotFound(key._1, key._2)
30+
sym
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+
)
36+
2437
extension (tpe: Type)
2538
def toSemanticSig(using LinkMode, Context, SemanticSymbolBuilder)(sym: Symbol): s.Signature =
2639
def enterParamRef(tpe: Type): Unit =
@@ -110,14 +123,12 @@ class TypeOps:
110123
): (Type, List[List[Symbol]], List[Symbol]) = t match {
111124
case mt: MethodType =>
112125
val syms = mt.paramNames.flatMap { paramName =>
113-
val key = (mt, paramName)
114-
paramRefSymtab.get(key)
126+
paramRefSymtab.getOrErr((mt, paramName))
115127
}
116128
flatten(mt.resType, paramss :+ syms, tparams)
117129
case pt: PolyType =>
118130
val syms = pt.paramNames.flatMap { paramName =>
119-
val key = (pt, paramName)
120-
paramRefSymtab.get(key)
131+
paramRefSymtab.getOrErr((pt, paramName))
121132
}
122133
// there shouldn't multiple type params
123134
flatten(pt.resType, paramss, syms)
@@ -185,7 +196,7 @@ class TypeOps:
185196

186197
case tref: ParamRef =>
187198
val key = (tref.binder, tref.paramName)
188-
paramRefSymtab.get(key) match {
199+
paramRefSymtab.getOrErr(key) match {
189200
case Some(ref) =>
190201
val ssym = ref.symbolName
191202
tref match {
@@ -243,7 +254,7 @@ class TypeOps:
243254
val stpe = s.IntersectionType(flattenParent(parent))
244255

245256
val decls = refinedInfos.flatMap { (name, _) =>
246-
refinementSymtab.get((rt, name))
257+
refinementSymtab.getOrErr((rt, name))
247258
}
248259
val sdecls = decls.sscopeOpt(using LinkMode.HardlinkChildren)
249260
s.StructuralType(stpe, sdecls)
@@ -337,6 +348,7 @@ class TypeOps:
337348
case _ => false
338349
}
339350

351+
340352
object SymbolScopeOps:
341353
import Scala3.given
342354
extension (syms: List[Symbol])

0 commit comments

Comments
 (0)