Skip to content

Unary methods should not have parenthesis #6192

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

Closed
nicolasstucki opened this issue Mar 29, 2019 · 3 comments
Closed

Unary methods should not have parenthesis #6192

nicolasstucki opened this issue Mar 29, 2019 · 3 comments

Comments

@nicolasstucki
Copy link
Contributor

Unarry methods cannot be called with parenthesis, hence a unary method defined with parenthesis will never be callable.

class Foo {
  def unary_- : Int = 1
  def unary_!(): Int = 2 // error should be identified here

  def foo = {
    -this
    !this // error: method unary_! must be called with () argument
  }
}
@nicolasstucki
Copy link
Contributor Author

This came from the community build

[warn] -- [E100] Syntax Migration Warning: /tmp/3/community-build/community-projects/squants/shared/src/main/scala/squants/AbstractQuantityNumeric.scala:33:21 
[warn] 33 |  def negate(x: A) = -x
[warn]    |                     ^^
[warn]    |                     method unary_- must be called with () argument

@odersky
Copy link
Contributor

odersky commented Apr 1, 2019

I think we are good as is for this. The error message looks fine to me. I don't think we need to add furher checks.

@odersky odersky closed this as completed Apr 1, 2019
@som-snytt
Copy link
Contributor

This disposition preserves a puzzler!

Someone had grumbled that no one would ever define a unary with parens, so it's gratifying to see the real-world example. If Scala is the real world.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants