diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index bdc6a03f6949..2d51360bd321 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -3981,8 +3981,7 @@ 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) @@ -3990,6 +3989,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer 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))), @@ -3997,6 +3997,10 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer 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 { @@ -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 @@ -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 diff --git a/tests/neg/i15414.scala b/tests/neg/i15414.scala new file mode 100644 index 000000000000..9565276a5752 --- /dev/null +++ b/tests/neg/i15414.scala @@ -0,0 +1,4 @@ +class C() +object C { + val c = apply() // error +} \ No newline at end of file