-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Generate a readable error message if syntectic copy
method clashes with user-defined one
#209
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
Comments
Could manifest itself either as an error-message during checking or as a data-race assertion. Both can be seen https://travis-ci.org/lampepfl/dotty/builds/39506385 |
After a discussion with @odersky: |
copy
method with default arguments clashes with user-defined onecopy
method clashes with user-defined one
copy
method clashes with user-defined onecopy
method clashes with user-defined one
See scala#209 for explanation.
The copy method subverts attempts to use private constructors for case Jason On Monday, November 3, 2014, Dmitry Petrashko [email protected]
|
See scala#209 for explanation.
See scala#209 for explanation.
The current error message for this is case class Foo(a: Int) {
def copy(i: Int): Foo = ???
} -- Error: Foo.scala:1:21 -------------------------------------------------------
1 |case class Foo(a: Int) {
| ^
| cannot merge
| method copy: (a: Int): Foo and
| method copy: (i: Int): Foo;
| they are both defined in class Foo but have matching signatures
| (a: Int): Foo and
| (i: Int): Foo
| when seen as members of Foo(Foo.this)
-- Error: Foo.scala:2:6 --------------------------------------------------------
2 | def copy(i: Int): Foo = ???
| ^
| method copy is already defined as method copy: (a: Int): Foo
| (the definitions have matching type signatures) We should catch this situation earlier and tell the user why this synthesized method exists. We also need to do this for other syntesized methods such as |
But it seems case classes with private constructors have public apply methods, so there's no protection afforded by this. Except if we make the apply method private as well. |
Leaving open, because we might rethink once more in detail how constructor accessibility affects methods created for a case class. |
Syntectic
copy
method in case classses has default arguments.And leads to compilation error if user had also defined a
copy
method with default arguments as in dotty-staging@202a377#diff-ca3386647f5386b6f70e99f1a9e188cdR1982I guess desugaring should not synthesize a
copy
method if user had defined any method namedcopy
.The text was updated successfully, but these errors were encountered: