Skip to content

Simplify newExpr #10973

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

Merged
merged 1 commit into from
Jan 4, 2021
Merged
Changes from all commits
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
31 changes: 11 additions & 20 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3589,26 +3589,17 @@ class Typer extends Namer

/** Convert constructor proxy reference to a new expression */
def newExpr =
def recur(tpt: Tree, pt: Type): Tree = pt.revealIgnored match
case PolyProto(targs, pt1) =>
if targs.exists(_.isInstanceOf[NamedArg]) then
errorTree(tpt, "Named type argument not allowed in constructor application")
else
IntegratedTypeArgs(recur(AppliedTypeTree(tpt, targs), pt1))
case _ =>
typed(untpd.Select(untpd.New(untpd.TypedSplice(tpt)), nme.CONSTRUCTOR), pt)

tree match
case Select(qual, nme.apply) =>
val tycon = tree.tpe.widen.finalResultType.underlyingClassRef(refinementOK = false)
val tpt = qual match
case Ident(name) => cpy.Ident(qual)(name.toTypeName)
case Select(pre, name) => cpy.Select(qual)(pre, name.toTypeName)
recur(tpt.withType(tycon), pt)
.showing(i"convert creator $tree -> $result", typr)
case _ =>
throw AssertionError(i"bad case for newExpr: $tree, $pt")
end newExpr
val Select(qual, nme.apply) = tree; @unchecked
val tycon = tree.tpe.widen.finalResultType.underlyingClassRef(refinementOK = false)
val tpt = qual match
case Ident(name) => cpy.Ident(qual)(name.toTypeName)
case Select(pre, name) => cpy.Select(qual)(pre, name.toTypeName)
typed(
untpd.Select(
untpd.New(untpd.TypedSplice(tpt.withType(tycon))),
nme.CONSTRUCTOR),
pt)
.showing(i"convert creator $tree -> $result", typr)

tree match {
case _: MemberDef | _: PackageDef | _: Import | _: WithoutTypeOrPos[?] | _: Closure => tree
Expand Down