-
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.
Disallow some opaque type aliases in match type patterns
Disallow opaque type aliases in match type patterns in scopes where the alias is visible.
- Loading branch information
Showing
6 changed files
with
108 additions
and
17 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,7 @@ | ||
-- [E191] Type Error: tests/neg/named-tuples-strawman-2.scala:28:24 ---------------------------------------------------- | ||
28 | inline def toTuple: DropNames[NT] = x.asInstanceOf // error | ||
| ^^^^^^^^^^^^^ | ||
| The match type contains an illegal case: | ||
| case NamedTupleOps.NamedTuple[_, x] => x | ||
| The pattern contains an opaque type alias `NamedTuple` in the scope where its alias is known. | ||
| (this error can be ignored for now with `-source:3.3`) |
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,29 @@ | ||
import compiletime.* | ||
import compiletime.ops.int.* | ||
import compiletime.ops.boolean.! | ||
|
||
object NamedTupleDecomposition: | ||
import NamedTupleOps.* | ||
|
||
/** The names of the named tuple type `NT` */ | ||
type Names[NT <: AnyNamedTuple] <: Tuple = NT match | ||
case NamedTuple[n, _] => n | ||
|
||
/** The value types of the named tuple type `NT` */ | ||
type DropNames[NT <: AnyNamedTuple] <: Tuple = NT match | ||
case NamedTuple[_, x] => x | ||
|
||
object NamedTupleOps: | ||
|
||
opaque type AnyNamedTuple = Any | ||
|
||
opaque type NamedTuple[N <: Tuple, +X <: Tuple] >: X <: AnyNamedTuple = X | ||
|
||
export NamedTupleDecomposition.* | ||
|
||
object NamedTuple: | ||
def apply[N <: Tuple, X <: Tuple](x: X): NamedTuple[N, X] = x | ||
|
||
extension [NT <: AnyNamedTuple](x: NT) | ||
inline def toTuple: DropNames[NT] = x.asInstanceOf // error | ||
inline def names: Names[NT] = constValueTuple[Names[NT]] |
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,15 @@ | ||
-- [E191] Type Error: tests/neg/opaque-matches.scala:4:18 -------------------------------------------------------------- | ||
4 | type Fst[X] = X match // error | ||
| ^ | ||
| The match type contains an illegal case: | ||
| case NT.NT[a, b] => a | ||
| The pattern contains a type alias `NT`. | ||
| (this error can be ignored for now with `-source:3.3`) | ||
5 | case NT[a, b] => a | ||
-- [E191] Type Error: tests/neg/opaque-matches.scala:10:30 ------------------------------------------------------------- | ||
10 | inline def snd[NT](nt: NT): NTDecomposition.Snd[NT] = // error | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ | ||
| The match type contains an illegal case: | ||
| case NT.NT[a, b] => b | ||
| The pattern contains an opaque type alias `NT` in the scope where its alias is known. | ||
| (this error can be ignored for now with `-source:3.3`) |
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,19 @@ | ||
object NT: | ||
opaque type NT[A, B] = B | ||
|
||
type Fst[X] = X match // error | ||
case NT[a, b] => a | ||
|
||
inline def fst[NT](nt: NT): Fst[NT] = | ||
??? | ||
|
||
inline def snd[NT](nt: NT): NTDecomposition.Snd[NT] = // error | ||
??? | ||
|
||
object NTDecomposition: | ||
|
||
type Snd[X] = X match | ||
case NT.NT[a, b] => b | ||
|
||
|
||
|
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