Skip to content

Commit aa6459e

Browse files
authored
Merge pull request #3772 from dotty-staging/fix-#3012
Fix #3012: Avoid swallowing multiple ()'s
2 parents 39e466d + c299da9 commit aa6459e

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,21 @@ object Typer {
6262
if (!tree.isEmpty && !tree.isInstanceOf[untpd.TypedSplice] && ctx.typerState.isGlobalCommittable)
6363
assert(tree.pos.exists, s"position not set for $tree # ${tree.uniqueId}")
6464

65+
/** A context property that indicates the owner of any expressions to be typed in the context
66+
* if that owner is different from the context's owner. Typically, a context with a class
67+
* as owner would have a local dummy as ExprOwner value.
68+
*/
6569
private val ExprOwner = new Property.Key[Symbol]
70+
71+
/** An attachment on a Select node with an `apply` field indicating that the `apply`
72+
* was inserted by the Typer.
73+
*/
6674
private val InsertedApply = new Property.Key[Unit]
75+
76+
/** An attachment on a tree `t` occurring as part of a `t()` where
77+
* the `()` was dropped by the Typer.
78+
*/
79+
private val DroppedEmptyArgs = new Property.Key[Unit]
6780
}
6881

6982
class Typer extends Namer with TypeAssigner with Applications with Implicits with Dynamic with Checking with Docstrings {
@@ -1862,6 +1875,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
18621875
*
18631876
* 0th strategy: If `tree` overrides a nullary method, mark the prototype
18641877
* so that the argument is dropped and return `tree` itself.
1878+
* (but do this at most once per tree).
18651879
*
18661880
* After that, two strategies are tried, and the first that is successful is picked.
18671881
* If neither of the strategies are successful, continues with`fallBack`.
@@ -1899,7 +1913,9 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
18991913

19001914
pt match {
19011915
case pt @ FunProto(Nil, _, _)
1902-
if tree.symbol.allOverriddenSymbols.exists(_.info.isNullaryMethod) =>
1916+
if tree.symbol.allOverriddenSymbols.exists(_.info.isNullaryMethod) &&
1917+
tree.getAttachment(DroppedEmptyArgs).isEmpty =>
1918+
tree.putAttachment(DroppedEmptyArgs, ())
19031919
pt.markAsDropped()
19041920
tree
19051921
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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
object a extends fuz.Fuzbar {
3+
override def str = ""
4+
str()()()()()() // error: missing argument
5+
str()() // error: missing argument
6+
str() // ok
7+
str // ok
8+
}

0 commit comments

Comments
 (0)