Skip to content

Commit 19ea673

Browse files
committed
Flag unloadable references as errors
#14783 shows an example where an implicit reference was generated that started in a type. The backend then crashed since it could not emit instructions to load that reference. We now detect such references when they are created and flag them as errors. We need to separately fix the issue that created the bad reference in the first place.
1 parent ee6733a commit 19ea673

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

compiler/src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -404,18 +404,21 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
404404
}
405405

406406
/** A tree representing the same reference as the given type */
407-
def ref(tp: NamedType)(using Context): Tree =
407+
def ref(tp: NamedType, needLoad: Boolean = true)(using Context): Tree =
408408
if (tp.isType) TypeTree(tp)
409409
else if (prefixIsElidable(tp)) Ident(tp)
410410
else if (tp.symbol.is(Module) && ctx.owner.isContainedIn(tp.symbol.moduleClass))
411411
followOuterLinks(This(tp.symbol.moduleClass.asClass))
412412
else if (tp.symbol hasAnnotation defn.ScalaStaticAnnot)
413413
Ident(tp)
414-
else {
414+
else
415415
val pre = tp.prefix
416416
if (pre.isSingleton) followOuterLinks(singleton(pre.dealias)).select(tp)
417-
else Select(TypeTree(pre), tp)
418-
}
417+
else
418+
val res = Select(TypeTree(pre), tp)
419+
if needLoad && !res.symbol.isStatic then
420+
throw new TypeError(em"cannot establish a reference to $res")
421+
res
419422

420423
def ref(sym: Symbol)(using Context): Tree =
421424
ref(NamedType(sym.owner.thisType, sym.name, sym.denot))

compiler/src/dotty/tools/dotc/typer/Applications.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ trait Applications extends Compatibility {
705705
def fail(msg: Message): Unit =
706706
ok = false
707707
def appPos: SrcPos = NoSourcePosition
708-
@threadUnsafe lazy val normalizedFun: Tree = ref(methRef)
708+
@threadUnsafe lazy val normalizedFun: Tree = ref(methRef, needLoad = false)
709709
init()
710710
}
711711

0 commit comments

Comments
 (0)