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.
Merge pull request scala#7364 from dotty-staging/fix-6570-1
Fix scala#6570: Don't reduce match types with empty scrutinies
- Loading branch information
Showing
9 changed files
with
234 additions
and
52 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
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,33 @@ | ||
import scala.Tuple._ | ||
|
||
trait Trait1 | ||
trait Trait2 | ||
|
||
case class Box[+T](t: T) | ||
|
||
type N[x] = x match { | ||
case Box[String] => Trait1 | ||
case Box[Int] => Trait2 | ||
} | ||
|
||
trait Cov[+T] | ||
type M[t] = t match { | ||
case Cov[x] => N[x] | ||
} | ||
|
||
trait Root[A] { | ||
def thing: M[A] | ||
} | ||
|
||
class Asploder extends Root[Cov[Box[Int & String]]] { | ||
def thing = new Trait1 {} // error | ||
} | ||
|
||
object Main { | ||
def foo[T <: Cov[Box[Int]]](c: Root[T]): Trait2 = c.thing | ||
|
||
def explode = foo(new Asploder) | ||
|
||
def main(args: Array[String]): Unit = | ||
explode | ||
} |
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,109 @@ | ||
object Base { | ||
trait Trait1 | ||
trait Trait2 | ||
type N[t] = t match { | ||
case String => Trait1 | ||
case Int => Trait2 | ||
} | ||
} | ||
import Base._ | ||
|
||
object UpperBoundParametricVariant { | ||
trait Cov[+T] | ||
type M[t] = t match { | ||
case Cov[x] => N[x] | ||
} | ||
|
||
trait Root[A] { | ||
def thing: M[A] | ||
} | ||
|
||
trait Child[A <: Cov[Int]] extends Root[A] | ||
|
||
// we reduce `M[T]` to `Trait2`, even though we cannot be certain of that | ||
def foo[T <: Cov[Int]](c: Child[T]): Trait2 = c.thing | ||
|
||
class Asploder extends Child[Cov[String & Int]] { | ||
def thing = new Trait1 {} // error | ||
} | ||
|
||
def explode = foo(new Asploder) // ClassCastException | ||
} | ||
|
||
object InheritanceVariant { | ||
// allows binding a variable to the UB of a type member | ||
type Trick[a] = { type A <: a } | ||
type M[t] = t match { case Trick[a] => N[a] } | ||
|
||
trait Root { | ||
type B | ||
def thing: M[B] | ||
} | ||
|
||
trait Child extends Root { type B <: { type A <: Int } } | ||
|
||
def foo(c: Child): Trait2 = c.thing | ||
|
||
class Asploder extends Child { | ||
type B = { type A = String & Int } | ||
def thing = new Trait1 {} // error | ||
} | ||
} | ||
|
||
object ThisTypeVariant { | ||
type Trick[a] = { type A <: a } | ||
type M[t] = t match { case Trick[a] => N[a] } | ||
|
||
trait Root { | ||
def thing: M[this.type] | ||
} | ||
|
||
trait Child extends Root { type A <: Int } | ||
|
||
def foo(c: Child): Trait2 = c.thing | ||
|
||
class Asploder extends Child { | ||
type A = String & Int | ||
def thing = new Trait1 {} // error | ||
} | ||
} | ||
|
||
object ParametricVariant { | ||
type Trick[a] = { type A <: a } | ||
type M[t] = t match { case Trick[a] => N[a] } | ||
|
||
trait Root[B] { | ||
def thing: M[B] | ||
} | ||
|
||
trait Child[B <: { type A <: Int }] extends Root[B] | ||
|
||
def foo[T <: { type A <: Int }](c: Child[T]): Trait2 = c.thing | ||
|
||
class Asploder extends Child[{ type A = String & Int }] { | ||
def thing = new Trait1 {} // error | ||
} | ||
|
||
def explode = foo(new Asploder) | ||
} | ||
|
||
object UpperBoundVariant { | ||
trait Cov[+T] | ||
type M[t] = t match { case Cov[t] => N[t] } | ||
|
||
trait Root { | ||
type A | ||
def thing: M[A] | ||
} | ||
|
||
trait Child extends Root { type A <: Cov[Int] } | ||
|
||
def foo(c: Child): Trait2 = c.thing | ||
|
||
class Asploder extends Child { | ||
type A = Cov[String & Int] | ||
def thing = new Trait1 {} // error | ||
} | ||
|
||
def explode = foo(new Asploder) | ||
} |
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
Oops, something went wrong.