Skip to content

Fix #3012: Avoid swallowing multiple ()'s #3772

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 8, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 5 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ object Typer {

private val ExprOwner = new Property.Key[Symbol]
private val InsertedApply = new Property.Key[Unit]
private val DroppedEmptyArgs = new Property.Key[Unit]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think every key should have a documentation comment :).

}

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

pt match {
case pt @ FunProto(Nil, _, _)
if tree.symbol.allOverriddenSymbols.exists(_.info.isNullaryMethod) =>
if tree.symbol.allOverriddenSymbols.exists(_.info.isNullaryMethod) &&
tree.getAttachment(DroppedEmptyArgs).isEmpty =>
tree.putAttachment(DroppedEmptyArgs, ())
pt.markAsDropped()
tree
case _ =>
Expand Down
4 changes: 4 additions & 0 deletions tests/neg/i3012/Fuzbar.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package fuz;
public interface Fuzbar {
public String str();
}
5 changes: 5 additions & 0 deletions tests/neg/i3012/a.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

object a extends fuz.Fuzbar {
override def str = ""
str()()()()()() // error: missing argument
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a line with just str()() to check that it's also an error? A pos test with str and str() would be useful too.

}