-
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
Refine criterion when to widen types in match type reduction. We now do not widen if the compared-against type contains variant named type parameters. This is intended to fix the soundness problem in #17149. Fixes #17149 Fixes #15926 Todos: - [ ] Check & fix neg test failures - [ ] Add more tests - [ ] Also consider approximating abstract types to lower bounds. This is completely missing so far. There are neither tests nor an implementation. - [ ] Update the docs on match types to explain what goes on here.
- Loading branch information
Showing
5 changed files
with
74 additions
and
3 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 |
---|---|---|
|
@@ -48,6 +48,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
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,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] |