Skip to content

Commit

Permalink
Flag unloadable references as errors
Browse files Browse the repository at this point in the history
scala#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.
  • Loading branch information
odersky committed Mar 31, 2022
1 parent ee6733a commit 19ea673
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 7 additions & 4 deletions compiler/src/dotty/tools/dotc/ast/tpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -404,18 +404,21 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
}

/** A tree representing the same reference as the given type */
def ref(tp: NamedType)(using Context): Tree =
def ref(tp: NamedType, needLoad: Boolean = true)(using Context): Tree =
if (tp.isType) TypeTree(tp)
else if (prefixIsElidable(tp)) Ident(tp)
else if (tp.symbol.is(Module) && ctx.owner.isContainedIn(tp.symbol.moduleClass))
followOuterLinks(This(tp.symbol.moduleClass.asClass))
else if (tp.symbol hasAnnotation defn.ScalaStaticAnnot)
Ident(tp)
else {
else
val pre = tp.prefix
if (pre.isSingleton) followOuterLinks(singleton(pre.dealias)).select(tp)
else Select(TypeTree(pre), tp)
}
else
val res = Select(TypeTree(pre), tp)
if needLoad && !res.symbol.isStatic then
throw new TypeError(em"cannot establish a reference to $res")
res

def ref(sym: Symbol)(using Context): Tree =
ref(NamedType(sym.owner.thisType, sym.name, sym.denot))
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Applications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ trait Applications extends Compatibility {
def fail(msg: Message): Unit =
ok = false
def appPos: SrcPos = NoSourcePosition
@threadUnsafe lazy val normalizedFun: Tree = ref(methRef)
@threadUnsafe lazy val normalizedFun: Tree = ref(methRef, needLoad = false)
init()
}

Expand Down

0 comments on commit 19ea673

Please sign in to comment.