-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Automatic Type Derivation causes Assertion Error for Non-Static Enum #11174
Comments
deusaquilus
changed the title
Automatic Type Derivation fails for Non-Static Enum
Automatic Type Derivation causes Assertion Error for Non-Static Enum
Jan 20, 2021
It will also break if you define class MainClass {
given EnumerateNames[Int] with {
def apply: String = "int"
}
inline given auto[T]:EnumerateNames[T] = EnumerateNames.derived
def deriveEnumerateNames[T](using en: EnumerateNames[T]) = en.apply
def run = {
enum Shape:
case Square(width: Int, height: Int) extends Shape
case Circle(radius: Int) extends Shape
println( deriveEnumerateNames[Shape] )
}
} |
nicolasstucki
added
area:metaprogramming
area:inline
and removed
area:metaprogramming
labels
Jan 20, 2021
Minimized import scala.compiletime.{summonFrom, summonInline, erasedValue}
import scala.deriving.Mirror
trait EnumerateNames[T]
object EnumerateNames {
inline def derived[T]: EnumerateNames[T] =
summonFrom {
case ev: Mirror.Of[T] =>
inline ev match
case m: Mirror.ProductOf[T] => ???
case m: Mirror.SumOf[T] =>
inline erasedValue[m.MirroredElemTypes] match
case _: (tpe *: _) => summonInline[EnumerateNames[tpe]]
case _: EmptyTuple =>
???
}
}
class MainClass {
enum Shape:
case Point
inline given auto[T]: EnumerateNames[T] = EnumerateNames.derived[T]
def shapeNames: EnumerateNames[Shape] = EnumerateNames.derived[Shape]
} |
Same problem with shapeless-3 |
bishabosha
added a commit
to dotty-staging/dotty
that referenced
this issue
Sep 3, 2021
add a new method healPrefix which converts ThisTypes wrapping a Module into a TermRef and subsitutes ThisType of enclosing classes with matching parts of the prefix of the summoned mirror fixes scala#12328 fixes scala#11174
bishabosha
added a commit
to dotty-staging/dotty
that referenced
this issue
Mar 2, 2022
add a new method healPrefix which converts ThisTypes wrapping a Module into a TermRef and subsitutes ThisType of enclosing classes with matching parts of the prefix of the summoned mirror fixes scala#12328 fixes scala#11174
bishabosha
added a commit
to dotty-staging/dotty
that referenced
this issue
Apr 1, 2022
add a new method healPrefix which converts ThisTypes wrapping a Module into a TermRef and subsitutes ThisType of enclosing classes with matching parts of the prefix of the summoned mirror fixes scala#12328 fixes scala#11174
bishabosha
added a commit
to dotty-staging/dotty
that referenced
this issue
Apr 1, 2022
add a new method healPrefix which converts ThisTypes wrapping a Module into a TermRef and subsitutes ThisType of enclosing classes with matching parts of the prefix of the summoned mirror fixes scala#12328 fixes scala#11174
bishabosha
added a commit
to dotty-staging/dotty
that referenced
this issue
May 16, 2022
add a new method healPrefix which converts ThisTypes wrapping a Module into a TermRef and subsitutes ThisType of enclosing classes with matching parts of the prefix of the summoned mirror fixes scala#12328 fixes scala#11174
bishabosha
added a commit
to dotty-staging/dotty
that referenced
this issue
May 16, 2022
add a new method healPrefix which converts ThisTypes wrapping a Module into a TermRef and subsitutes ThisType of enclosing classes with matching parts of the prefix of the summoned mirror fixes scala#12328 fixes scala#11174
bishabosha
added a commit
to dotty-staging/dotty
that referenced
this issue
May 18, 2022
add a new method healPrefix which converts ThisTypes wrapping a Module into a TermRef and subsitutes ThisType of enclosing classes with matching parts of the prefix of the summoned mirror fixes scala#12328 fixes scala#11174 use do not force symbols add safety for unknown type experiment with TypeOps.refineUsingParent support hk types rebase fixes disable for scala2x generic product nonstatic simplify a bit add more tests find common prefix of and/or types refine implementation based on runtime tests experiment with supertypes remove prefix splice in companionref
Just tripped across this issue as well in the Scala 3 upgrade of the borer macros... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Minimized code
First, let's implement a really simple type derivation that just prints something for every given type in a product/coproduct
Then let's create a class that defines an enum and an automatic derivation for types:
Then let's call that class:
Output
A very large error happens:
Expectation
Compilation should work and "int, int, int" should be returned.
Workaround
Moving the enum to a static place (e.g. into an object) seems to solve the problem.
Repo
Repository with code sample can be found here:
https://github.com/deusaquilus/enum_summon
The text was updated successfully, but these errors were encountered: