File tree 3 files changed +40
-2
lines changed
compiler/src/dotty/tools/dotc/typer
3 files changed +40
-2
lines changed Original file line number Diff line number Diff line change @@ -1465,8 +1465,10 @@ class Typer extends Namer
1465
1465
case _ =>
1466
1466
if tree.isInline then checkInInlineContext(" inline match" , tree.srcPos)
1467
1467
val sel1 = typedExpr(tree.selector)
1468
- val selType = fullyDefinedType(sel1.tpe, " pattern selector" , tree.span).widen
1469
-
1468
+ val rawSelectorTpe = fullyDefinedType(sel1.tpe, " pattern selector" , tree.span)
1469
+ val selType = rawSelectorTpe match
1470
+ case c : ConstantType if tree.isInline => c
1471
+ case otherTpe => otherTpe.widen
1470
1472
/** Extractor for match types hidden behind an AppliedType/MatchAlias */
1471
1473
object MatchTypeInDisguise {
1472
1474
def unapply (tp : AppliedType ): Option [MatchType ] = tp match {
Original file line number Diff line number Diff line change
1
+ package repro
2
+
3
+ import compiletime .{constValue , erasedValue }
4
+
5
+ sealed trait ValidateExprInt
6
+
7
+ class And [A <: ValidateExprInt , B <: ValidateExprInt ] extends ValidateExprInt
8
+ class GreaterThan [T <: Int ] extends ValidateExprInt
9
+
10
+ object Repro :
11
+ inline def validate [E <: ValidateExprInt ](v : Int ): String =
12
+ val failMsg = validateV[E ](v)
13
+ if failMsg == " neverPass" then " neverPass"
14
+ else " something else"
15
+
16
+ transparent inline def validateV [E <: ValidateExprInt ](v : Int ): String =
17
+ inline erasedValue[E ] match
18
+ case _ : GreaterThan [t] =>
19
+ " GreaterThan"
20
+ case _ : And [a, b] =>
21
+ inline validateV[a](v) match
22
+ case " " =>
23
+ validateV[b](v)
24
+ case other =>
25
+ other
26
+
27
+ @ main def test (): Unit =
28
+ println(validate[And [GreaterThan [10 ], GreaterThan [12 ]]](5 ))
Original file line number Diff line number Diff line change
1
+ transparent inline def f : String =
2
+ inline 10 match
3
+ case _ =>
4
+ inline " foo" match
5
+ case x : String => x
6
+
7
+ def test =
8
+ inline val failMsg = f
You can’t perform that action at this time.
0 commit comments