Skip to content

Commit 6b1d67c

Browse files
committed
Don't allow single apply's to be used as constructor proxies
The previous commits allowed them but that caused runtime errors in Specs2 since `apply` was bound to something different from before. Since this is a weird corner case it's better not to allow it. As long as we do not crash we are good. The error message we get now is: constructor proxy `apply` cannot be used as a value which is also a bit strange, but since this is a truly weird corner case it's not worth it to finetune this.
1 parent 0a8d2e1 commit 6b1d67c

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3997,6 +3997,10 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
39973997
pt)
39983998
.showing(i"convert creator $tree -> $result", typr)
39993999

4000+
def isApplyProxy(tree: Tree) = tree match
4001+
case Select(_, nme.apply) => tree.symbol.isAllOf(ApplyProxyFlags)
4002+
case _ => false
4003+
40004004
tree match {
40014005
case _: MemberDef | _: PackageDef | _: Import | _: WithoutTypeOrPos[?] | _: Closure => tree
40024006
case _ => tree.tpe.widen match {
@@ -4012,7 +4016,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
40124016
adaptOverloaded(ref)
40134017
}
40144018
case poly: PolyType if !(ctx.mode is Mode.Type) =>
4015-
if tree.symbol.isAllOf(ApplyProxyFlags) then newExpr
4019+
if isApplyProxy(tree) then newExpr
40164020
else if pt.isInstanceOf[PolyProto] then tree
40174021
else
40184022
var typeArgs = tree match
@@ -4026,7 +4030,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
40264030
readaptSimplified(handleStructural(tree))
40274031
else pt match {
40284032
case pt: FunProto =>
4029-
if tree.symbol.isAllOf(ApplyProxyFlags) then newExpr
4033+
if isApplyProxy(tree) then newExpr
40304034
else adaptToArgs(wtp, pt)
40314035
case pt: PolyProto if !wtp.isImplicitMethod =>
40324036
tryInsertApplyOrImplicit(tree, pt, locked)(tree) // error will be reported in typedTypeApply

tests/neg/i15414.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class C()
2+
object C {
3+
val c = apply() // error
4+
}

tests/new/i15414.scala

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)