Skip to content
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

Disallow nilary (empty parenthesis) of prefix unary methods #9241

Closed
soronpo opened this issue Jun 25, 2020 · 7 comments · Fixed by #12749 or #14372
Closed

Disallow nilary (empty parenthesis) of prefix unary methods #9241

soronpo opened this issue Jun 25, 2020 · 7 comments · Fixed by #12749 or #14372
Assignees
Projects
Milestone

Comments

@soronpo
Copy link
Contributor

soronpo commented Jun 25, 2020

Same as Scala 2 bug scala/bug#12055

Minimized code

class Foo {
  def unary_~() : Foo = this

  // also bad
  def unary_+()(implicit pos: Long): Foo = this
}
val f = new Foo
val f2 = ~f //method unary_~ must be called with () argument

https://scastie.scala-lang.org/NKZQM3d8RrGYRYFoewJyQw

Expectation

Auto-application is disallowed and there a prefix def with a nilary(empty parenthesis) creates an error that cannot be avoided while maintaining a prefix position. To resolve this, we need to deprecate this possibility from the definition site.

@odersky
Copy link
Contributor

odersky commented Jun 25, 2020

It's not quite clear how this should be done. Do you want to disallow all parameters on methods named unary_n? what exactly is the pattern? I fear we will need quite a bit of spec language to cover this.

Also, is it really worth it? With a single unit test for your operator you'll find out that this will not work.

@nicolasstucki
Copy link
Contributor

This is the same as #6192 which we closed without solving it.

@soronpo
Copy link
Contributor Author

soronpo commented Jun 25, 2020

There was a PR submitted to Scala 2 to resolve this issue:
scala/scala#9085

@soronpo
Copy link
Contributor Author

soronpo commented Jun 25, 2020

It's not quite clear how this should be done. Do you want to disallow all parameters on methods named unary_n? what exactly is the pattern? I fear we will need quite a bit of spec language to cover this.

The PR in Scala 2 is sufficient enough. It removes a single empty-parent option from unary_x defs. We could go further and disallow all non-given parameter blocks from unary_x defs (given block support is required).

@odersky
Copy link
Contributor

odersky commented Jun 25, 2020

I note that #9085 comes without a spec, which makes it incomplete. I would be interested to see what a spec would look like. I suspect it would look rather out of place.

@sjrd
Copy link
Member

sjrd commented Jun 25, 2020

A spec would be very similar to number 3. in https://dotty.epfl.ch/docs/reference/changed-features/operators.html#details-1. Something like:

The first parameter list of a unary operator method must not be empty. As a reminder from Section Prefix Operations, a unary operator is one whose name is "unary_op" for op in + - ! ~.

@odersky
Copy link
Contributor

odersky commented Jan 3, 2021

I think somebody else should take this on.

@bishabosha bishabosha added this to Unassigned in Spree Jun 8, 2021
@nicolasstucki nicolasstucki moved this from Unassigned to Assigned in Spree Jun 8, 2021
@nicolasstucki nicolasstucki self-assigned this Jun 8, 2021
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jun 8, 2021
@nicolasstucki nicolasstucki moved this from Assigned to Fixed in Spree Jun 8, 2021
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jun 9, 2021
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jun 9, 2021
@Kordyjan Kordyjan added this to the 3.0.2 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment