-
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.
Refine criterion when to widen types (#17180)
- Loading branch information
Showing
15 changed files
with
192 additions
and
45 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 |
---|---|---|
|
@@ -50,6 +50,7 @@ i6505.scala | |
i15158.scala | ||
i15155.scala | ||
i15827.scala | ||
i17149.scala | ||
|
||
# Opaque type | ||
i5720.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
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,17 @@ | ||
type Ext1[S] = S match { | ||
case Seq[t] => t | ||
} | ||
type Ext2[S] = S match { | ||
case Seq[_] => Int | ||
} | ||
type Ext3[S] = S match { | ||
case Array[t] => t | ||
} | ||
type Ext4[S] = S match { | ||
case Array[_] => Int | ||
} | ||
def foo[T <: Seq[Any], A <: Array[B], B] = | ||
summon[Ext1[T] =:= T] // error | ||
summon[Ext2[T] =:= Int] // ok | ||
summon[Ext3[A] =:= B] // ok | ||
summon[Ext4[A] =:= Int] // ok |
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,7 @@ | ||
trait Show[-A >: Nothing] | ||
|
||
type MT1[I <: Show[Nothing], N] = I match | ||
case Show[a] => N match | ||
case Int => a | ||
|
||
val a = summon[MT1[Show[String], Int] =:= 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,24 @@ | ||
// like pos/i15926.scala | ||
// but with the nested match type extracted | ||
// which is a workaround that fixed the problem | ||
sealed trait Nat | ||
final case class Zero() extends Nat | ||
final case class Succ[+N <: Nat]() extends Nat | ||
|
||
final case class Neg[+N <: Succ[Nat]]() | ||
|
||
type Sum[X, Y] = Y match | ||
case Zero => X | ||
case Succ[y] => Sum[Succ[X], y] | ||
|
||
type IntSum[A, B] = B match | ||
case Neg[b] => IntSumNeg[A, b] | ||
|
||
type IntSumNeg[A, B] = A match | ||
case Neg[a] => Neg[Sum[a, B]] | ||
|
||
type One = Succ[Zero] | ||
type Two = Succ[One] | ||
|
||
class Test: | ||
def test() = summon[IntSum[Neg[One], Neg[One]] =:= Neg[Two]] |
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 @@ | ||
// like pos/i15926.scala | ||
// but minimised to the subset of paths needed | ||
// to fail the specific test case | ||
sealed trait Nat | ||
final case class Zero() extends Nat | ||
final case class Succ[+N <: Nat]() extends Nat | ||
|
||
final case class Neg[+N <: Succ[Nat]]() | ||
|
||
type Sum[X, Y] = Y match | ||
case Zero => X | ||
case Succ[y] => Sum[Succ[X], y] | ||
|
||
type IntSum[A, B] = B match | ||
case Neg[b] => A match | ||
case Neg[a] => Neg[Sum[a, b]] | ||
|
||
type One = Succ[Zero] | ||
type Two = Succ[One] | ||
|
||
class Test: | ||
def test() = summon[IntSum[Neg[One], Neg[One]] =:= Neg[Two]] |
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,28 @@ | ||
|
||
@main def main(): Unit = | ||
println(summon[Sum[Minus[Succ[Zero]], Minus[Succ[Zero]]] =:= Minus[Succ[Succ[Zero]]]]) | ||
|
||
sealed trait IntT | ||
sealed trait NatT extends IntT | ||
final case class Zero() extends NatT | ||
final case class Succ[+N <: NatT](n: N) extends NatT | ||
final case class Minus[+N <: Succ[NatT]](n: N) extends IntT | ||
|
||
type NatSum[X <: NatT, Y <: NatT] <: NatT = Y match | ||
case Zero => X | ||
case Succ[y] => NatSum[Succ[X], y] | ||
|
||
type NatDif[X <: NatT, Y <: NatT] <: IntT = Y match | ||
case Zero => X | ||
case Succ[y] => X match | ||
case Zero => Minus[Y] | ||
case Succ[x] => NatDif[x, y] | ||
|
||
type Sum[X <: IntT, Y <: IntT] <: IntT = Y match | ||
case Zero => X | ||
case Minus[y] => X match | ||
case Minus[x] => Minus[NatSum[x, y]] | ||
case _ => NatDif[X, y] | ||
case _ => X match | ||
case Minus[x] => NatDif[Y, x] | ||
case _ => NatSum[X, Y] |
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,6 @@ | ||
type Ext[S <: Seq[_]] = S match { | ||
case Seq[t] => t | ||
} | ||
|
||
val _ = implicitly[Ext[Seq[Int]] =:= Int] // e.scala: Cannot prove that e.Ext[Seq[Int]] =:= Int | ||
val _ = summon[Ext[Seq[Int]] =:= Int] |