Skip to content

Commit ee265a6

Browse files
committed
Fix #3012: Avoid swallowing multiple ()'s
Allow dropping at most one () if a method is called that exists in both ()T and => T forms.
1 parent 7e402a7 commit ee265a6

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ object Typer {
6464

6565
private val ExprOwner = new Property.Key[Symbol]
6666
private val InsertedApply = new Property.Key[Unit]
67+
private val DroppedEmptyArgs = new Property.Key[Unit]
6768
}
6869

6970
class Typer extends Namer with TypeAssigner with Applications with Implicits with Dynamic with Checking with Docstrings {
@@ -1862,6 +1863,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
18621863
*
18631864
* 0th strategy: If `tree` overrides a nullary method, mark the prototype
18641865
* so that the argument is dropped and return `tree` itself.
1866+
* (but do this at most once per tree).
18651867
*
18661868
* After that, two strategies are tried, and the first that is successful is picked.
18671869
* If neither of the strategies are successful, continues with`fallBack`.
@@ -1899,7 +1901,9 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
18991901

19001902
pt match {
19011903
case pt @ FunProto(Nil, _, _)
1902-
if tree.symbol.allOverriddenSymbols.exists(_.info.isNullaryMethod) =>
1904+
if tree.symbol.allOverriddenSymbols.exists(_.info.isNullaryMethod) &&
1905+
tree.getAttachment(DroppedEmptyArgs).isEmpty =>
1906+
tree.putAttachment(DroppedEmptyArgs, ())
19031907
pt.markAsDropped()
19041908
tree
19051909
case _ =>

tests/neg/i3012/Fuzbar.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package fuz;
2+
public interface Fuzbar {
3+
public String str();
4+
}

tests/neg/i3012/a.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
object a extends fuz.Fuzbar {
3+
override def str = ""
4+
str()()()()()() // error: missing argument
5+
}

0 commit comments

Comments
 (0)