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

Keep default getters next to the original definition #5965

Merged
merged 2 commits into from Jun 28, 2017

Conversation

dragos
Copy link
Contributor

@dragos dragos commented Jun 27, 2017

While this was the intention, this never worked for synthetic methods
with defaults, like case class factory methods. Also fix the matching
logic for constructors.

Fix scala/bug#10343

While this was the intention, this never worked for synthetic methods
with defaults, like case class factory methods. Also fix the matching
logic for constructors.
@scala-jenkins scala-jenkins added this to the 2.12.3 milestone Jun 27, 2017
@dragos dragos requested a review from lrytz June 27, 2017 19:16
@som-snytt
Copy link
Contributor

I wonder if there's a useful test? I tweaked something similar once, I'll have to look if there was a test for it. I bet there was no test. We don't need no stinkin' tests.

@dragos
Copy link
Contributor Author

dragos commented Jun 28, 2017

Good point, @som-snytt. The bug report has a repro, I have to dive into the bytecode test infrastructure, maybe there's something I could use.

@@ -3187,7 +3187,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
def matches(stat: Tree, synt: Tree) = (stat, synt) match {
// synt is default arg for stat
case (DefDef(_, statName, _, _, _, _), DefDef(mods, syntName, _, _, _, _)) =>
mods.hasDefault && syntName.toString.startsWith(statName.toString)
mods.hasDefault && syntName.decodedName.startsWith(statName)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interestingly this is the line that fixes scala/bug#10343

Copy link
Contributor Author

@dragos dragos Jun 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, I just wanted to have a full stable order even when apply has default values (or copy).. so I went ahead with the sort as well ;-)

@lrytz
Copy link
Member

lrytz commented Jun 28, 2017

@dragos I pushed a test case directly to your branch (muhaha)

assertEquals(pm.methods.asScala.map(_.name).toList,
// after typer, `"$lessinit$greater$default$1"` is next to `<init>`, but the constructor phase
// and code gen change module constructors around. the second `apply` is a bridge, created in erasure.
List("<clinit>", "$lessinit$greater$default$1", "toString", "apply", "apply$default$1", "unapply", "readResolve", "apply", "<init>"))
Copy link
Member

@retronym retronym Jun 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Side note: when creating the names of lambda impl methods corresponding to lambdas in constructors, we opted for "new$" rather than "$lessinit$greater" (taking a leaf from the book of javac)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is just using the method name as a prefix for default getters, and constructors should still be called <init> AFAIK. It's probably simpler not to add a different naming convention for default getters for constructor parameters, although I agree the method name looks terrible.

@lrytz lrytz merged commit a35c3c9 into scala:2.12.x Jun 28, 2017
@dragos
Copy link
Contributor Author

dragos commented Jun 28, 2017

@lrytz was lightning fast to come up with a test case, and now I learned about bytecode tests :) Simpler than I thought!

Thanks for the quick turnaround!

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