-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix #9873: no longer use scala.Enum as parents of enums #9877
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
bishabosha
wants to merge
14
commits into
scala:master
from
dotty-staging:topic/enum-remove-scala-enum
Closed
Changes from 4 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
8392705
fix #9873: deprecate scala.Enum, no longer use it as parent of enums
bishabosha 913d831
fix tests
bishabosha 4e91dbe
error on custom definition of enum getters
bishabosha 2351587
add enumLabel to Mirror.Sum
bishabosha 489a1af
gen ordinal and enumLabel more lazily
bishabosha 5a75bab
adjust message for error
bishabosha 5a46667
only ordinal method is optional
bishabosha faa69ac
remove special case error
bishabosha 96a8af9
revert add enumLabel to Mirror
bishabosha 4d04804
use classSymbol
bishabosha 7adfa3f
adjust comment
bishabosha 4e3d6e4
Remove untpd.EnumGetters
bishabosha be11253
delay enter ordinal symbol
bishabosha 4951a75
refactor synthetic flag for ordinal + enumlabel
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
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,76 @@ | ||
package scala | ||
|
||
import quoted._ | ||
|
||
object deriving { | ||
|
||
/** Mirrors allows typelevel access to enums, case classes and objects, and their sealed parents. | ||
*/ | ||
sealed trait Mirror { | ||
|
||
/** The mirrored *-type */ | ||
type MirroredMonoType | ||
|
||
/** The name of the type */ | ||
type MirroredLabel <: String | ||
|
||
/** The names of the product elements */ | ||
type MirroredElemLabels <: Tuple | ||
} | ||
|
||
object Mirror { | ||
|
||
/** The Mirror for a sum type */ | ||
trait Sum extends Mirror { self => | ||
/** The ordinal number of the case class of `x`. For enums, `ordinal(x) == x.ordinal` */ | ||
def ordinal(x: MirroredMonoType): Int | ||
/** The case label of the case class of `x`. For enums, `enumLabel(x) == x.enumLabel` */ | ||
def enumLabel(x: MirroredMonoType): String | ||
bishabosha marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
/** The Mirror for a product type */ | ||
trait Product extends Mirror { | ||
|
||
/** Create a new instance of type `T` with elements taken from product `p`. */ | ||
def fromProduct(p: scala.Product): MirroredMonoType | ||
} | ||
|
||
trait Singleton extends Product { | ||
type MirroredMonoType = this.type | ||
type MirroredType = this.type | ||
type MirroredElemTypes = EmptyTuple | ||
type MirroredElemLabels = EmptyTuple | ||
def fromProduct(p: scala.Product) = this | ||
} | ||
|
||
/** A proxy for Scala 2 singletons, which do not inherit `Singleton` directly */ | ||
class SingletonProxy(val value: AnyRef) extends Product { | ||
type MirroredMonoType = value.type | ||
type MirroredType = value.type | ||
type MirroredElemTypes = EmptyTuple | ||
type MirroredElemLabels = EmptyTuple | ||
def fromProduct(p: scala.Product) = value | ||
} | ||
|
||
type Of[T] = Mirror { type MirroredType = T; type MirroredMonoType = T ; type MirroredElemTypes <: Tuple } | ||
type ProductOf[T] = Mirror.Product { type MirroredType = T; type MirroredMonoType = T ; type MirroredElemTypes <: Tuple } | ||
type SumOf[T] = Mirror.Sum { type MirroredType = T; type MirroredMonoType = T; type MirroredElemTypes <: Tuple } | ||
} | ||
|
||
/** Helper class to turn arrays into products */ | ||
class ArrayProduct(val elems: Array[AnyRef]) extends Product { | ||
def this(size: Int) = this(new Array[AnyRef](size)) | ||
def canEqual(that: Any): Boolean = true | ||
def productElement(n: Int) = elems(n) | ||
def productArity = elems.length | ||
override def productIterator: Iterator[Any] = elems.iterator | ||
def update(n: Int, x: Any) = elems(n) = x.asInstanceOf[AnyRef] | ||
} | ||
|
||
/** The empty product */ | ||
object EmptyProduct extends ArrayProduct(Array.emptyObjectArray) | ||
|
||
/** Helper method to select a product element */ | ||
def productElement[T](x: Any, idx: Int) = | ||
x.asInstanceOf[Product].productElement(idx).asInstanceOf[T] | ||
} |
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
File renamed without changes.
36 changes: 0 additions & 36 deletions
36
library/src-non-bootstrapped/scala/runtime/EnumValueSerializationProxy.java
This file was deleted.
Oops, something went wrong.
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.