Skip to content

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

Closed
DarkDimius opened this issue Oct 31, 2014 · 6 comments
Assignees
Labels
area:reporting Error reporting including formatting, implicit suggestions, etc exp:intermediate help wanted itype:enhancement prio:low

Comments

@DarkDimius
Copy link
Contributor

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-ca3386647f5386b6f70e99f1a9e188cdR1982

I guess desugaring should not synthesize a copy method if user had defined any method named copy.

@DarkDimius
Copy link
Contributor Author

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

@DarkDimius
Copy link
Contributor Author

After a discussion with @odersky:
That's intended. Logic of deciding if copy method should be generated is too involved an to hard to maintain. And copy method would be always generated. Instead we could work on error message in future.

@DarkDimius DarkDimius changed the title Syntectic copy method with default arguments clashes with user-defined one Generata and readable error message if syntectic copy method clashes with user-defined one Nov 3, 2014
@DarkDimius DarkDimius changed the title Generata and readable error message if syntectic copy method clashes with user-defined one Generate a readable error message if syntectic copy method clashes with user-defined one Nov 3, 2014
DarkDimius added a commit to dotty-staging/dotty that referenced this issue Nov 3, 2014
@retronym
Copy link
Member

retronym commented Nov 3, 2014

The copy method subverts attempts to use private constructors for case
classes so being able to disable its generation is a useful idiom.

Jason

On Monday, November 3, 2014, Dmitry Petrashko [email protected]
wrote:

After a discussion with @odersky https://github.com/odersky:
That's intended. Logic of deciding if copy method should be generated is
too involved an to hard to maintain. And copy method would be always
generated. Instead we could work on error message in future.


Reply to this email directly or view it on GitHub
#209 (comment).

DarkDimius added a commit to dotty-staging/dotty that referenced this issue Nov 17, 2014
DarkDimius added a commit to dotty-staging/dotty that referenced this issue Nov 22, 2014
@smarter smarter added the area:reporting Error reporting including formatting, implicit suggestions, etc label Nov 18, 2015
@nicolasstucki
Copy link
Contributor

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 equals hashCode, apply, unapply, ...

@odersky
Copy link
Contributor

odersky commented Jan 27, 2018

@retronym

The copy method subverts attempts to use private constructors for case
classes so being able to disable its generation is a useful idiom.

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.

@odersky
Copy link
Contributor

odersky commented Jan 27, 2018

Leaving open, because we might rethink once more in detail how constructor accessibility affects methods created for a case class.

@odersky odersky self-assigned this Jan 27, 2018
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jan 24, 2019
nicolasstucki added a commit that referenced this issue Jan 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:reporting Error reporting including formatting, implicit suggestions, etc exp:intermediate help wanted itype:enhancement prio:low
Projects
None yet
Development

No branches or pull requests

5 participants