-
Notifications
You must be signed in to change notification settings - Fork 1.1k
remove dollar ordinal from Enum #9539
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
bishabosha
merged 10 commits into
scala:master
from
dotty-staging:topic/enum-reduce-bytecode
Aug 18, 2020
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d4d2e58
remove dollarordinal from Enum, reduce bytecode
bishabosha fcd6774
update semanticdb
bishabosha 0360b47
ensure methods only deleted if defined by enum syntax
bishabosha 9dd1e00
update desugar docs
bishabosha 06113ac
Simplification, do not generate methods if java
bishabosha ffbb127
assert more in enum-values-order test
bishabosha e34d09e
update docs
bishabosha c064338
prevent leaks with simple cases
bishabosha 8bdae8e
add case to mix simple and value java enum cases
bishabosha 58ca371
add test of aliasing java enum
bishabosha 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
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,9 @@ | ||
object Planet: | ||
final val G = 6.67300E-11 | ||
|
||
enum Planet(mass: Double, radius: Double) extends java.lang.Enum[Planet]: | ||
def surfaceGravity = Planet.G * mass / (radius * radius) | ||
def surfaceWeight(otherMass: Double) = otherMass * surfaceGravity | ||
|
||
case Mercury extends Planet(3.303e+23, 2.4397e6) | ||
case Venus extends Planet(4.869e+24, 6.0518e6) |
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,5 @@ | ||
object Lib1: | ||
trait MyJavaEnum[E <: java.lang.Enum[E]] extends java.lang.Enum[E] | ||
|
||
object Lib2: | ||
type JavaEnumAlias[E <: java.lang.Enum[E]] = java.lang.Enum[E] |
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,9 @@ | ||
enum Color1 extends Lib1.MyJavaEnum[Color1]: | ||
case Red, Green, Blue | ||
|
||
enum Color2 extends Lib2.JavaEnumAlias[Color2]: | ||
case Red, Green, Blue | ||
|
||
@main def Test = | ||
assert(Color1.Green.ordinal == 1) | ||
assert(Color2.Blue.ordinal == 2) |
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 |
---|---|---|
@@ -1,8 +1,80 @@ | ||
/** immutable hashmaps (as of 2.13 collections) only store up to 4 entries in insertion order */ | ||
enum LatinAlphabet { case A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z } | ||
|
||
enum LatinAlphabet2 extends java.lang.Enum[LatinAlphabet2] { case A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z } | ||
|
||
enum LatinAlphabet3[+T] extends java.lang.Enum[LatinAlphabet3[_]] { case A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z } | ||
|
||
object Color: | ||
trait Pretty | ||
enum Color extends java.lang.Enum[Color]: | ||
case Red, Green, Blue | ||
case Aqua extends Color with Color.Pretty | ||
case Grey, Black, White | ||
case Emerald extends Color with Color.Pretty | ||
case Brown | ||
|
||
@main def Test = | ||
import LatinAlphabet._ | ||
val ordered = Seq(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z) | ||
|
||
assert(ordered sameElements LatinAlphabet.values) | ||
|
||
def testLatin() = | ||
|
||
val ordinals = Seq(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25) | ||
val labels = Seq("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z") | ||
|
||
def testLatin1() = | ||
import LatinAlphabet._ | ||
val ordered = Seq(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z) | ||
|
||
assert(ordered sameElements LatinAlphabet.values) | ||
assert(ordinals == ordered.map(_.ordinal)) | ||
assert(labels == ordered.map(_.productPrefix)) | ||
|
||
def testLatin2() = | ||
import LatinAlphabet2._ | ||
val ordered = Seq(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z) | ||
|
||
assert(ordered sameElements LatinAlphabet2.values) | ||
assert(ordinals == ordered.map(_.ordinal)) | ||
assert(labels == ordered.map(_.name)) | ||
|
||
def testLatin3() = | ||
import LatinAlphabet3._ | ||
val ordered = Seq(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z) | ||
|
||
assert(ordered sameElements LatinAlphabet3.values) | ||
assert(ordinals == ordered.map(_.ordinal)) | ||
assert(labels == ordered.map(_.name)) | ||
|
||
testLatin1() | ||
testLatin2() | ||
testLatin3() | ||
|
||
end testLatin | ||
|
||
def testColor() = | ||
import Color._ | ||
val ordered = Seq(Red, Green, Blue, Aqua, Grey, Black, White, Emerald, Brown) | ||
val ordinals = Seq(0, 1, 2, 3, 4, 5, 6, 7, 8) | ||
val labels = Seq("Red", "Green", "Blue", "Aqua", "Grey", "Black", "White", "Emerald", "Brown") | ||
|
||
assert(ordered sameElements Color.values) | ||
assert(ordinals == ordered.map(_.ordinal)) | ||
assert(labels == ordered.map(_.name)) | ||
|
||
def isPretty(c: Color): Boolean = c match | ||
case _: Pretty => true | ||
case _ => false | ||
|
||
assert(!isPretty(Brown)) | ||
assert(!isPretty(Grey)) | ||
assert(isPretty(Aqua)) | ||
assert(isPretty(Emerald)) | ||
assert(Emerald.getClass != Aqua.getClass) | ||
assert(Aqua.getClass != Grey.getClass) | ||
assert(Grey.getClass == Brown.getClass) | ||
|
||
end testColor | ||
|
||
testLatin() | ||
testColor() |
Oops, something went wrong.
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.