Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid crash arising from trying to find conversions from polymorphic singleton types #18760

Merged
merged 2 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions compiler/src/dotty/tools/dotc/ast/tpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,19 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
def Apply(fn: Tree, args: List[Tree])(using Context): Apply = fn match
case Block(Nil, expr) =>
Apply(expr, args)
case _: RefTree | _: GenericApply | _: Inlined | _: Hole =>
ta.assignType(untpd.Apply(fn, args), fn, args)
case _ =>
assert(
fn.isInstanceOf[RefTree | GenericApply | Inlined | Hole] || ctx.reporter.errorsReported,
s"Illegal Apply function prefix: $fn"
)
assert(ctx.reporter.errorsReported)
ta.assignType(untpd.Apply(fn, args), fn, args)

def TypeApply(fn: Tree, args: List[Tree])(using Context): TypeApply = fn match
case Block(Nil, expr) =>
TypeApply(expr, args)
case _: RefTree | _: GenericApply =>
ta.assignType(untpd.TypeApply(fn, args), fn, args)
case _ =>
assert(
fn.isInstanceOf[RefTree | GenericApply] || ctx.reporter.errorsReported,
s"Illegal TypeApply function prefix: $fn"
)
assert(ctx.reporter.errorsReported, s"unexpected tree for type application: $fn")
ta.assignType(untpd.TypeApply(fn, args), fn, args)

def Literal(const: Constant)(using Context): Literal =
Expand Down
8 changes: 7 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4366,7 +4366,13 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
case _ =>
adaptOverloaded(ref)
}
case poly: PolyType if !(ctx.mode is Mode.Type) =>
case poly: PolyType
if !(ctx.mode is Mode.Type) && dummyTreeOfType.unapply(tree).isEmpty =>
// If we are in a conversion from a TermRef with polymorphic underlying
// type, give up. In this case the typed `null` literal cannot be instantiated.
// Test case was but i18695.scala, but it got fixed by a different tweak in #18719.
// We leave test for this condition in as a defensive measure in case
// it arises somewhere else.
if isApplyProxy(tree) then newExpr
else if pt.isInstanceOf[PolyProto] then tree
else
Expand Down
Loading