-
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.
Always use baseType when constraining patternTp with scrutineeTp
In the following example: ``` type Cond[B <: Boolean] <: Tuple2[String, String] = B match ... type Decoded[B <: Boolean] = Cond[B] match case (h1, _) => Int ``` When constraining the `(h1, _)` pattern with `Cond[B]`, we incorrectly assumed we could constrain h1 with B, because `Cond[B]` is an applied type of which the baseType is Tuple2. The issue can be fixed in constrainSimplePatternType by obtaining the baseType for both the patternTp and scrutineeTp, with the most general base of the two. So in the above example, we wound constrain `B` with String by obtaining `(String, String)` from `Cond[B]`.
- Loading branch information
1 parent
960858d
commit 521ce95
Showing
2 changed files
with
34 additions
and
7 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,29 @@ | ||
|
||
import scala.compiletime.ops.string.{Length, Matches, Substring} | ||
|
||
def emptyContext(): Unit = | ||
summon[Decoded["Tuple(0, EmptyTuple)"] =:= 0 *: EmptyTuple] | ||
|
||
type Decoded[S <: String] = Matches[S, "Tuple(.+, .+)"] match | ||
case true => Parsed[Substring[S, 6, 19], 0, ""] match | ||
case (h, t) => Decoded["0"] *: EmptyTuple | ||
case false => 0 | ||
|
||
type Parsed[S <: String, I <: Int, A <: String] <: (String, String) = Matches[S, "other"] match | ||
case true => I match | ||
case 1 => ("", "") | ||
case _ => Parsed[Substring[S, 1, Length[S]], I, ""] | ||
case false => ("0", "EmptyTuple") | ||
|
||
|
||
object Minimization: | ||
|
||
type Cond[B <: Boolean] <: Tuple2[String, String] = B match | ||
case true => ("", "") | ||
case false => ("a", "b") | ||
|
||
type Decoded[B <: Boolean] = Cond[B] match | ||
case (h1, _) => Int | ||
|
||
val _: Decoded[false] = 1 | ||
|