forked from scala/scala3
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Take up scala#13780 again, but refine it so that abstract types are allowed in match type reduction as long as they uniquely instantiate type parameters of the type pattern. Fixes scala#11982
- Loading branch information
1 parent
ebacde8
commit de9c544
Showing
12 changed files
with
288 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
-- [E007] Type Mismatch Error: tests/neg/6570-1.scala:23:27 ------------------------------------------------------------ | ||
23 | def thing = new Trait1 {} // error | ||
| ^ | ||
| Found: Object with Trait1 {...} | ||
| Required: N[Box[Int & String]] | ||
| | ||
| Note: a match type could not be fully reduced: | ||
| | ||
| trying to reduce N[Box[Int & String]] | ||
| failed since selector Box[Int & String] | ||
| is uninhabited (there are no values of that type). | ||
| | ||
| longer explanation available when compiling with `-explain` | ||
-- [E007] Type Mismatch Error: tests/neg/6570-1.scala:36:54 ------------------------------------------------------------ | ||
36 | def foo[T <: Cov[Box[Int]]](c: Root[T]): Trait2 = c.thing // error | ||
| ^^^^^^^ | ||
| Found: M[T] | ||
| Required: Trait2 | ||
| | ||
| where: T is a type in method foo with bounds <: Cov[Box[Int]] | ||
| | ||
| | ||
| Note: a match type could not be fully reduced: | ||
| | ||
| trying to reduce M[T] | ||
| failed since selector T | ||
| does not uniquely determine parameter x in case Cov[x] => N[x] | ||
| The computed bounds for the parameter are: >: Box[Int]. | ||
| | ||
| longer explanation available when compiling with `-explain` |
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,39 @@ | ||
-- [E057] Type Mismatch Error: tests/neg/i11982.scala:9:34 ------------------------------------------------------------- | ||
9 | b: ValueOf[Tuple.Head[Tuple.Tail[X]]] // error | ||
| ^ | ||
| Type argument Tuple.Tail[X] does not conform to upper bound NonEmptyTuple | ||
| | ||
| Note: a match type could not be fully reduced: | ||
| | ||
| trying to reduce Tuple.Tail[X] | ||
| failed since selector X | ||
| does not uniquely determine parameter xs in case _ *: xs => xs | ||
| The computed bounds for the parameter are: >: Any *: EmptyTuple.type <: Tuple. | ||
| | ||
| longer explanation available when compiling with `-explain` | ||
-- [E057] Type Mismatch Error: tests/neg/i11982.scala:10:38 ------------------------------------------------------------ | ||
10 | ): Tuple2[Tuple.Head[X], Tuple.Head[Tuple.Tail[X]]] = // error | ||
| ^ | ||
| Type argument Tuple.Tail[X] does not conform to upper bound NonEmptyTuple | ||
| | ||
| Note: a match type could not be fully reduced: | ||
| | ||
| trying to reduce Tuple.Tail[X] | ||
| failed since selector X | ||
| does not uniquely determine parameter xs in case _ *: xs => xs | ||
| The computed bounds for the parameter are: >: Any *: EmptyTuple.type <: Tuple. | ||
| | ||
| longer explanation available when compiling with `-explain` | ||
-- [E057] Type Mismatch Error: tests/neg/i11982.scala:12:25 ------------------------------------------------------------ | ||
12 | type BB = Tuple.Head[Tuple.Tail[X]] // error | ||
| ^ | ||
| Type argument Tuple.Tail[X] does not conform to upper bound NonEmptyTuple | ||
| | ||
| Note: a match type could not be fully reduced: | ||
| | ||
| trying to reduce Tuple.Tail[X] | ||
| failed since selector X | ||
| does not uniquely determine parameter xs in case _ *: xs => xs | ||
| The computed bounds for the parameter are: >: Any *: EmptyTuple.type <: Tuple. | ||
| | ||
| longer explanation available when compiling with `-explain` |
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,27 @@ | ||
package tuplefun | ||
object Unpair { | ||
|
||
def pair[A, B](using a: ValueOf[A], b: ValueOf[B]): Tuple2[A, B] = | ||
(a.value, b.value) | ||
|
||
def unpair[X <: Tuple2[?, ?]]( | ||
using a: ValueOf[Tuple.Head[X]], | ||
b: ValueOf[Tuple.Head[Tuple.Tail[X]]] // error | ||
): Tuple2[Tuple.Head[X], Tuple.Head[Tuple.Tail[X]]] = // error | ||
type AA = Tuple.Head[X] | ||
type BB = Tuple.Head[Tuple.Tail[X]] // error | ||
pair[AA, BB](using a, b) | ||
} | ||
|
||
object UnpairApp { | ||
import Unpair._ | ||
|
||
type Tshape = ("msg", 42) | ||
|
||
// the following won't compile when in the same file as Unpair | ||
val p1: ("msg", 42) = unpair[Tshape] | ||
|
||
@main def pairHello: Unit = | ||
assert(p1 == ("msg", 42)) | ||
println(p1) | ||
} |
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,34 @@ | ||
-- [E007] Type Mismatch Error: tests/neg/i13780.scala:18:31 ------------------------------------------------------------ | ||
18 | def int[X <: Y]: Int = unpair[X] // error | ||
| ^^^^^^^^^ | ||
| Found: Head[X] | ||
| Required: Int | ||
| | ||
| where: X is a type in method int with bounds <: B.this.Y | ||
| | ||
| | ||
| Note: a match type could not be fully reduced: | ||
| | ||
| trying to reduce Head[X] | ||
| failed since selector X | ||
| does not uniquely determine parameter a in case (a, b) => a | ||
| The computed bounds for the parameter are: >: Int. | ||
| | ||
| longer explanation available when compiling with `-explain` | ||
-- [E007] Type Mismatch Error: tests/neg/i13780.scala:23:37 ------------------------------------------------------------ | ||
23 | def string[X <: Y]: String = unpair[X] // error | ||
| ^^^^^^^^^ | ||
| Found: Head[X] | ||
| Required: String | ||
| | ||
| where: X is a type in method string with bounds <: C.this.Y | ||
| | ||
| | ||
| Note: a match type could not be fully reduced: | ||
| | ||
| trying to reduce Head[X] | ||
| failed since selector X | ||
| does not uniquely determine parameter a in case (a, b) => a | ||
| The computed bounds for the parameter are: >: String. | ||
| | ||
| longer explanation available when compiling with `-explain` |
Oops, something went wrong.