-
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.
Merge pull request #12902 from tgodzik/fix-12715
Do no widen constant type on selector type in inline matches
- Loading branch information
Showing
3 changed files
with
40 additions
and
2 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,28 @@ | ||
package repro | ||
|
||
import compiletime.{constValue, erasedValue} | ||
|
||
sealed trait ValidateExprInt | ||
|
||
class And[A <: ValidateExprInt, B <: ValidateExprInt] extends ValidateExprInt | ||
class GreaterThan[T <: Int] extends ValidateExprInt | ||
|
||
object Repro: | ||
inline def validate[E <: ValidateExprInt](v: Int): String = | ||
val failMsg = validateV[E](v) | ||
if failMsg == "neverPass" then "neverPass" | ||
else "something else" | ||
|
||
transparent inline def validateV[E <: ValidateExprInt](v: Int): String = | ||
inline erasedValue[E] match | ||
case _: GreaterThan[t] => | ||
"GreaterThan" | ||
case _: And[a, b] => | ||
inline validateV[a](v) match | ||
case "" => | ||
validateV[b](v) | ||
case other => | ||
other | ||
|
||
@main def test(): Unit = | ||
println(validate[And[GreaterThan[10], GreaterThan[12]]](5)) |
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,8 @@ | ||
transparent inline def f: String = | ||
inline 10 match | ||
case _ => | ||
inline "foo" match | ||
case x : String => x | ||
|
||
def test = | ||
inline val failMsg = f |