Skip to content
Merged
Show file tree
Hide file tree
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
12 changes: 8 additions & 4 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3981,22 +3981,26 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer

/** Convert constructor proxy reference to a new expression */
def newExpr =
val Select(qual, nme.apply) = tree: @unchecked
val tycon = tree.tpe.widen.finalResultType.underlyingClassRef(refinementOK = false)
val qual = qualifier(tree)
val tpt = qual match
case Ident(name) =>
cpy.Ident(qual)(name.toTypeName)
case Select(pre, name) =>
cpy.Select(qual)(pre, name.toTypeName)
case qual: This if qual.symbol.is(ModuleClass) =>
cpy.Ident(qual)(qual.symbol.name.sourceModuleName.toTypeName)
val tycon = tree.tpe.widen.finalResultType.underlyingClassRef(refinementOK = false)
typed(
untpd.Select(
untpd.New(untpd.TypedSplice(tpt.withType(tycon))),
nme.CONSTRUCTOR),
pt)
.showing(i"convert creator $tree -> $result", typr)

def isApplyProxy(tree: Tree) = tree match
case Select(_, nme.apply) => tree.symbol.isAllOf(ApplyProxyFlags)
case _ => false

tree match {
case _: MemberDef | _: PackageDef | _: Import | _: WithoutTypeOrPos[?] | _: Closure => tree
case _ => tree.tpe.widen match {
Expand All @@ -4012,7 +4016,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
adaptOverloaded(ref)
}
case poly: PolyType if !(ctx.mode is Mode.Type) =>
if tree.symbol.isAllOf(ApplyProxyFlags) then newExpr
if isApplyProxy(tree) then newExpr
else if pt.isInstanceOf[PolyProto] then tree
else
var typeArgs = tree match
Expand All @@ -4026,7 +4030,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
readaptSimplified(handleStructural(tree))
else pt match {
case pt: FunProto =>
if tree.symbol.isAllOf(ApplyProxyFlags) then newExpr
if isApplyProxy(tree) then newExpr
else adaptToArgs(wtp, pt)
case pt: PolyProto if !wtp.isImplicitMethod =>
tryInsertApplyOrImplicit(tree, pt, locked)(tree) // error will be reported in typedTypeApply
Expand Down
4 changes: 4 additions & 0 deletions tests/neg/i15414.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class C()
object C {
val c = apply() // error
}