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

forbid default values for extension parameters #12460

Open
unkarjedy opened this issue May 13, 2021 · 5 comments · May be fixed by #17321
Open

forbid default values for extension parameters #12460

unkarjedy opened this issue May 13, 2021 · 5 comments · May be fixed by #17321

Comments

@unkarjedy
Copy link
Contributor

Compiler version

scalaVersion := "3.0.0-RC3"

Minimized code

Currently this compiles fine:

extension (x: String = "123")
  def f2 = x.reverse

Expectation

Seems that there are no use cases for it and only misleads
Probably a compiler error should be shown here.

@unkarjedy
Copy link
Contributor Author

note that default arguments are still acceptable in using parameters

locally {
    extension (x: String)(using s: String = "default value")
      def f1: String = x.reverse
    
    "my string".f1
  }

@unkarjedy
Copy link
Contributor Author

we may also prohibit by-name parameters in extensions,
because while even a regular argument to a by-name parameter might be surprising,
such as bar(foo()),
it's much more unexpected that foo().bar() might result in calling bar() without calling foo()

@SethTisue SethTisue added the Spree Suitable for a future Spree label Jan 30, 2023
@Sporarum
Copy link
Contributor

Discussing this with @mbovel, we believe we should put these checks in Refchecks
(As opposed to in the parser)

@Sporarum
Copy link
Contributor

You can find our work over there:
#17321

I left some TODOs to point at what still needs to be done

@som-snytt
Copy link
Contributor

som-snytt commented May 2, 2023

I thought extension methods were just methods. I find the departure from regularity surprising, but since the issue has been discussed, there must be an obvious case of misleading that I don't see. I mean obvious but not to me.

The by-name case is the same as right-associative operators.

Edit: I meant to say, it sounds like a lint.

@mbovel mbovel removed the Spree Suitable for a future Spree label Jan 30, 2024
@mbovel mbovel linked a pull request Nov 3, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants