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

Constructor properties are not properly copied #9267

Closed
scabug opened this issue Apr 10, 2015 · 3 comments
Closed

Constructor properties are not properly copied #9267

scabug opened this issue Apr 10, 2015 · 3 comments
Assignees

Comments

@scabug
Copy link

scabug commented Apr 10, 2015

The matchesName method in scala.tools.nsc.transform.Constructors.scala currently matches any parameter which starts with the param.name, followed by the join symbol ($). This has the possibility of wrongly matching a parameter during compilation which will silently compile without warnings and introduce problems in runtime.

A minimal reproducible is easy, and will create the same problem in all use-case versions of Scala:

scala> case class Invoice(`total tax`: Int, total: Int)
defined class Invoice

scala> Invoice(`total tax` = 20, total = 120)
res0: Invoice = Invoice(20,20)

scala> res0.total
res1: Int = 20

A proposal would be to change the method from

def matchesName(param: Symbol) = param.name == name ||
  param.name.startsWith(name + nme.NAME_JOIN_STRING)

to

def matchesName(param: Symbol) = param.name == name ||
  param.name == name.append(nme.NAME_JOIN_STRING)

I'll make a PR with the failing test, to discuss the potential solution.

@scabug
Copy link
Author

scabug commented Apr 10, 2015

Imported From: https://issues.scala-lang.org/browse/SI-9267?orig=1
Reporter: @melezov
Affected Versions: 2.9.3, 2.10.5, 2.11.6
See #8831
Attachments:

@scabug
Copy link
Author

scabug commented Apr 10, 2015

@retronym said:
Hi Marko,

I'm merging this with #8831. Could you please reference that ticket in your patch, and read through the comments over there?

Here was my prototype at a fix: scala/scala@2.11.x...retronym:ticket/8831

@scabug scabug closed this as completed Apr 10, 2015
@scabug
Copy link
Author

scabug commented Apr 10, 2015

@melezov said:
Ah, seems I only searched for constructor issues, my bad.
Also, my analysis seems to be a bit off as I didn't account for digits following $, so I closed the PR.

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

No branches or pull requests

2 participants