-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #4985: Generate productElementName for case classes #5617
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
User(name=Susan, age=42) | ||
ユーザー(名前=Susan, 年齢=42) | ||
U$er(na$me=Susan, a$ge=42) | ||
type(for=Susan, if=42) | ||
contains spaces(first param=Susan, second param=42) | ||
Symbols(::=Susan, ||=42) | ||
MultipleParamLists(a=Susan, b=42) | ||
AuxiliaryConstructor(a=Susan, b=42) | ||
OverloadedApply(a=Susan, b=123) | ||
PrivateMembers(a=10, b=20, c=30, d=40, e=50, f=60) | ||
NoParams() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// These methods are not yet on Product.scala (added in 2.13.x) | ||
trait Product2_13 extends Product { | ||
def productElementName(n: Int): String | ||
|
||
/** An iterator over the names of all the elements of this product. | ||
*/ | ||
def productElementNames: Iterator[String] = new scala.collection.AbstractIterator[String] { | ||
private[this] var c: Int = 0 | ||
private[this] val cmax = productArity | ||
|
||
def hasNext = c < cmax | ||
|
||
def next() = { | ||
val result = productElementName(c); c += 1; result | ||
} | ||
} | ||
} | ||
|
||
case class User(name: String, age: Int) extends Product2_13 | ||
|
||
case class ユーザー(名前: String, 年齢: Int) extends Product2_13 | ||
|
||
case class U$er(na$me: String, a$ge: Int) extends Product2_13 | ||
|
||
case class `type`(`for`: String, `if`: Int) extends Product2_13 | ||
|
||
case class `contains spaces`(`first param`: String, `second param`: Int) extends Product2_13 | ||
|
||
case class Symbols(:: : String, || : Int) extends Product2_13 | ||
|
||
case class MultipleParamLists(a: String, b: Int)(c: Boolean) extends Product2_13 | ||
|
||
case class AuxiliaryConstructor(a: String, b: Int) extends Product2_13 { | ||
def this(x: String) = { | ||
this(x, 123) | ||
} | ||
} | ||
|
||
case class OverloadedApply(a: String, b: Int) extends Product2_13 | ||
object OverloadedApply { | ||
def apply(x: String): OverloadedApply = | ||
new OverloadedApply(x, 123) | ||
} | ||
|
||
case class NoParams() extends Product2_13 | ||
|
||
//case class DefinesProductElementName(a: String, b: Int) extends Product2_13 { | ||
// override def productElementName(n: Int): String = "foo" | ||
//} | ||
|
||
//trait A { | ||
// override def productElementName(n: Int): String = "overriden" | ||
//} | ||
//case class InheritsProductElementName(a: String, b: Int) extends A | ||
// | ||
//trait B extends Product2_13 { | ||
// override def productElementName(n: Int): String = "overriden" | ||
//} | ||
//case class InheritsProductElementName_Override(a: String, b: Int) extends B | ||
// | ||
//trait C { self: Product => | ||
// override def productElementName(n: Int): String = "overriden" | ||
//} | ||
//case class InheritsProductElementName_Override_SelfType(a: String, b: Int) extends C | ||
|
||
case class PrivateMembers(a: Int, private val b: Int, c: Int, private val d: Int, e: Int, private val f: Int) extends Product2_13 | ||
|
||
object Test extends App { | ||
def pretty(p: Product2_13): String = | ||
p.productElementNames.zip(p.productIterator) | ||
.map { case (name, value) => s"$name=$value" } | ||
.mkString(p.productPrefix + "(", ", ", ")") | ||
|
||
println(pretty(User("Susan", 42))) | ||
println(pretty(ユーザー("Susan", 42))) | ||
println(pretty(U$er("Susan", 42))) | ||
println(pretty(`type`("Susan", 42))) | ||
println(pretty(`contains spaces`("Susan", 42))) | ||
println(pretty(Symbols("Susan", 42))) | ||
println(pretty(MultipleParamLists("Susan", 42)(true))) | ||
println(pretty(AuxiliaryConstructor("Susan", 42))) | ||
println(pretty(OverloadedApply("Susan"))) | ||
// println(pretty(DefinesProductElementName("Susan", 42))) | ||
|
||
// // uses the synthetic, not the one defined in the trait | ||
// println(pretty(InheritsProductElementName("Susan", 42))) | ||
// | ||
// // uses the override defined in the trait | ||
// println(pretty(InheritsProductElementName_Override("Susan", 42))) | ||
// | ||
// // uses the synthetic, not the one defined in the trait | ||
// println(pretty(InheritsProductElementName_Override_SelfType("Susan", 42))) | ||
|
||
println(pretty(PrivateMembers(10, 20, 30, 40, 50, 60))) | ||
println(pretty(NoParams())) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.