-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Freeze GADTs more when comparing type member infos
- Loading branch information
Showing
12 changed files
with
217 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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 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 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,31 @@ | ||
enum SUB[-L, +R]: | ||
case Refl[C]() extends SUB[C, C] | ||
|
||
trait Tag { type T } | ||
|
||
def foo[A, B, X <: Tag { type T <: A } ]( | ||
e: SUB[X, Tag { type T <: B }], | ||
x: A, | ||
): B = e match { | ||
case SUB.Refl() => | ||
// SUB.Refl.unapply[?C](e) | ||
// ?C >: X => cstr: C = X..Any | ||
// ?C <: Tag { T = Nothing..B } => cstr: C = X..Tag { T = Nothing..B } | ||
// SUB[Tag { T = Nothing..Int }, Tag { T = Nothing..String }] | ||
// A = Int | ||
// B = String | ||
// X = Tag { T = Nothing..Nothing } | ||
// X <: Tag { T = Nothing..A } | ||
// SUB[X, Tag { T = Nothing..B }] | ||
// SUB[Tag { T = Nothing..A }, Tag { T = Nothing..B }], approxLHS | ||
// Tag { T = Nothing..A } <: C <: Tag { T = Nothing..B }] | ||
// Tag { T = Nothing..A } <: Tag { T = Nothing..B } | ||
// A <: B | ||
x // error: Found: (x: A) Required: B | ||
} | ||
|
||
def bad(x: Int): String = | ||
foo[Int, String, Tag { type T = Nothing }](SUB.Refl(), x) // cast Int to String | ||
|
||
object Test: | ||
def main(args: Array[String]): Unit = bad(1) // was: ClassCastException: class java.lang.Integer cannot be cast to class java.lang.String |
This file contains 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,22 @@ | ||
enum SUB[-A, +B]: | ||
case Refl[C]() extends SUB[C, C] | ||
|
||
trait Tag { type T } | ||
|
||
def foo[L, H, X <: Tag { type T >: L <: H }]( | ||
e: SUB[X, Tag { type T = Int }], | ||
x: Int, | ||
): L = e match { | ||
case SUB.Refl() => | ||
// X <: C and C <: Tag { T = Int } | ||
// X <: Tag { T = Int } | ||
// Tag { T >: L <: H } <: Tag { T = Int } | ||
// Int <: L and H <: Int | ||
x // error | ||
} | ||
|
||
def bad(x: Int): String = | ||
foo[Nothing, Any, Tag { type T = Int }](SUB.Refl(), x) // cast Int to String! | ||
|
||
object Test: | ||
def main(args: Array[String]): Unit = bad(1) // was: ClassCastException: class java.lang.Integer cannot be cast to class java.lang.String |
This file contains 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,31 @@ | ||
enum SUB[-A, +B]: | ||
case Refl[C]() extends SUB[C, C] | ||
|
||
trait Tag { type T } | ||
|
||
def foo[L](g: Tag { type T >: L <: Int })( | ||
e: SUB[g.type, Tag { type T = Int }], | ||
x: Int, | ||
): L = e match { | ||
case SUB.Refl() => | ||
// L = Nothing | ||
// C = t | ||
// g := Tag { T = Int..Int } | ||
// g <: Tag { T = Nothing..Int } | ||
// SUB[g, Tag { T = Int..Int }] | ||
// SUB[Tag { T = Nothing..Int }, Tag { T = Int..Int }] | ||
// SUB[Tag { T = L..Int }, Tag { T = Int..Int }] <:< SUB[C, C] | ||
// Tag { T = L..Int } <: C <: Tag { T = Int..Int }] | ||
// Tag { T = L..Int } <: Tag { T = Int..Int } | ||
// Int <: L | ||
x // error | ||
} | ||
|
||
def bad(x: Int): String = | ||
val s: Tag { type T = Int } = new Tag { type T = Int } | ||
val t: Tag { type T >: Nothing <: Int } & s.type = s | ||
val e: SUB[t.type, Tag { type T = Int }] = SUB.Refl[t.type]() | ||
foo[Nothing](t)(e, x) // cast Int to String! | ||
|
||
object Test: | ||
def main(args: Array[String]): Unit = bad(1) // was: ClassCastException: class java.lang.Integer cannot be cast to class java.lang.String |
12 changes: 12 additions & 0 deletions
12
tests/pos-macros/i15485.fallout2-monocle/Derivation_1.scala
This file contains 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,12 @@ | ||
// Another minimisation (after tests/run-macros/i15485.fallout-monocle) | ||
// of monocle's GenIsoSpec.scala | ||
// which broke when fixing soundness in infering GADT constraints on refined types | ||
class Can[T] | ||
object Can: | ||
import scala.deriving.*, scala.quoted.* | ||
|
||
inline given derived[T](using inline m: Mirror.Of[T]): Can[T] = ${ impl('m) } | ||
|
||
private def impl[T](m: Expr[Mirror.Of[T]])(using Quotes, Type[T]): Expr[Can[T]] = m match | ||
case '{ $_ : Mirror.Sum { type MirroredElemTypes = met } } => '{ new Can[T] } | ||
case '{ $_ : Mirror.Product { type MirroredElemTypes = met } } => '{ new Can[T] } |
This file contains 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,3 @@ | ||
class Test: | ||
def test = | ||
Can.derived[EmptyTuple] |
10 changes: 10 additions & 0 deletions
10
tests/pos-macros/i15485.fallout3-monocle/Derivation_1.scala
This file contains 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,10 @@ | ||
import scala.deriving.*, scala.quoted.* | ||
|
||
object Iso: | ||
transparent inline def fields[S <: Product](using m: Mirror.ProductOf[S]): Int = ${ Impl.apply[S]('m) } | ||
|
||
object Impl: | ||
def apply[S <: Product](m: Expr[Mirror.ProductOf[S]])(using Quotes, Type[S]): Expr[Int] = | ||
import quotes.reflect.* | ||
m match | ||
case '{ type a <: Tuple; $m: Mirror.ProductOf[S] { type MirroredElemTypes = `a` } } => '{ 1 } |
This file contains 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,4 @@ | ||
class Test: | ||
def test = | ||
case object Foo | ||
val iso = Iso.fields[Foo.type] |
16 changes: 16 additions & 0 deletions
16
tests/run-macros/i15485.fallout-monocle/Derivation_1.scala
This file contains 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,16 @@ | ||
import scala.deriving.*, scala.quoted.* | ||
|
||
trait Foo[T]: | ||
def foo: Int | ||
|
||
// A minimisation of monocle's GenIsoSpec.scala | ||
// which broke when fixing soundness in infering GADT constraints on refined types | ||
object Foo: | ||
inline given derived[T](using inline m: Mirror.Of[T]): Foo[T] = ${ impl('m) } | ||
|
||
private def impl[T](m: Expr[Mirror.Of[T]])(using qctx: Quotes, tpe: Type[T]): Expr[Foo[T]] = m match | ||
case '{ $m : Mirror.Product { type MirroredElemTypes = EmptyTuple } } => '{ FooN[T](0) } | ||
case '{ $m : Mirror.Product { type MirroredElemTypes = a *: EmptyTuple } } => '{ FooN[T](1) } | ||
case '{ $m : Mirror.Product { type MirroredElemTypes = mirroredElemTypes } } => '{ FooN[T](9) } | ||
|
||
class FooN[T](val foo: Int) extends Foo[T] |
This file contains 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 @@ | ||
final case class Box(value: Int) derives Foo |
This file contains 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,3 @@ | ||
@main def Test = | ||
val foo = summon[Foo[Box]].foo | ||
assert(foo == 1, foo) |