forked from scala/scala3
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add GADT symbols when typing typing-ahead lambda bodies (scala#19644)
- Loading branch information
Showing
4 changed files
with
75 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
enum Op[A]: | ||
case Dup[T]() extends Op[(T, T)] | ||
|
||
def foo[R](f: [A] => Op[A] => R): R = ??? | ||
|
||
def test = | ||
foo([A] => (o: Op[A]) => o match | ||
case o: Op.Dup[u] => | ||
summon[A =:= (u, u)] // Error: Cannot prove that A =:= (u, u) | ||
() | ||
) | ||
foo[Unit]([A] => (o: Op[A]) => o match | ||
case o: Op.Dup[u] => | ||
summon[A =:= (u, u)] // Ok | ||
() | ||
) | ||
foo({ | ||
val f1 = [B] => (o: Op[B]) => o match | ||
case o: Op.Dup[u] => | ||
summon[B =:= (u, u)] // Also ok | ||
() | ||
f1 | ||
}) |
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,24 @@ | ||
sealed trait Op[A, B] { def giveA: A; def giveB: B } | ||
final case class Dup[T](x: T) extends Op[T, (T, T)] { def giveA: T = x; def giveB: (T, T) = (x, x) } | ||
|
||
class Test: | ||
def foo[R](f: [A, B] => (o: Op[A, B]) => R): R = ??? | ||
|
||
def m1: Unit = | ||
foo([A, B] => (o: Op[A, B]) => o match | ||
case o: Dup[t] => | ||
var a1: t = o.giveA | ||
var a2: A = o.giveA | ||
a1 = a2 | ||
a2 = a1 | ||
|
||
var b1: (t, t) = o.giveB | ||
var b2: B = o.giveB | ||
b1 = b2 | ||
b2 = b1 | ||
|
||
summon[A =:= t] // ERROR: Cannot prove that A =:= t. | ||
summon[B =:= (t, t)] // ERROR: Cannot prove that B =:= (t, 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,14 @@ | ||
enum Op[A, B]: | ||
case Dup[T]() extends Op[T, (T, T)] | ||
|
||
def foo[R](f: [A, B] => (o: Op[A, B]) => R): R = | ||
f(Op.Dup()) | ||
|
||
def test = | ||
foo([A, B] => (o: Op[A, B]) => { | ||
o match | ||
case o: Op.Dup[t] => | ||
summon[A =:= t] // ERROR: Cannot prove that A =:= t. | ||
summon[B =:= (t, t)] // ERROR: Cannot prove that B =:= (t, t). | ||
42 | ||
}) |