Skip to content

compiler doesn't allow to define matching .apply manually #10383

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
HuStmpHrrr opened this issue Jun 19, 2017 · 4 comments
Closed

compiler doesn't allow to define matching .apply manually #10383

HuStmpHrrr opened this issue Jun 19, 2017 · 4 comments

Comments

@HuStmpHrrr
Copy link

HuStmpHrrr commented Jun 19, 2017

following code generates error, which is not expected:

Welcome to Scala 2.12.1 (OpenJDK 64-Bit Server VM, Java 1.8.0_131).
Type in expressions for evaluation. Or try :help.

scala> :paste
// Entering paste mode (ctrl-D to finish)

case class Foo(s: String)
object Foo { def apply(s: String) = new Foo(s) }

// Exiting paste mode, now interpreting.

<pastie>:13: error: method apply is defined twice;
  the conflicting method apply was defined at line 14:25
       case class Foo(s: String)

from the specification:

If the object c already has a matching apply (or unapply) member, no new definition is added.

obviously, I am defining a matching .apply, hence the compiler shouldn't complain and simply accept my definition, instead of adding another definition of .apply. this behavior doesn't comply to the specification.

@HuStmpHrrr HuStmpHrrr changed the title compiler doesn't allow to define .apply manually compiler doesn't allow to define matching .apply manually Jun 19, 2017
@SethTisue
Copy link
Member

You're on 2.12.1, but this wasn't allowed until 2.12.2.

@HuStmpHrrr
Copy link
Author

@SethTisue can you elaborate? this part has existed at least in 2.11:

https://www.scala-lang.org/files/archive/spec/2.11/05-classes-and-objects.html#case-classes

@SethTisue
Copy link
Member

it was added in 2.11.11; see https://github.com/scala/scala/releases/tag/v2.11.11. 2.12.2 includes all the 2.11.9/2.11.10/2.11.11 changes; see https://github.com/scala/scala/releases/tag/v2.12.2

in 2.12.2, you can do it by default, but in 2.11.11, a late decision was made to put it behind -Xsource:2.12 instead of having it enabled by default. at that time that decision was made, the 2.11 spec change should also have been reverted. a PR fixing that in the 2.11 spec would be welcome

@SethTisue
Copy link
Member

note that in general, it isn't valid to reason that everything you see in any 2.11.x release is also present in every 2.12.x release. some 2.11.x releases are newer than some 2.12.x releases

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

No branches or pull requests

2 participants