Skip to content

Commit 9958339

Browse files
nicolasstuckimichelou
authored andcommitted
Remove call to constValue if it fails to expand
This avoids subsequet failures on this call. Fixes scala#11985
1 parent 0f23096 commit 9958339

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

compiler/src/dotty/tools/dotc/typer/Inliner.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -684,8 +684,11 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
684684
if (callTypeArgs.length == 1)
685685
if (inlinedMethod == defn.Compiletime_constValue) {
686686
val constVal = tryConstValue
687-
if (!constVal.isEmpty) return constVal
688-
report.error(em"not a constant type: ${callTypeArgs.head}; cannot take constValue", call.srcPos)
687+
if constVal.isEmpty then
688+
val msg = em"not a constant type: ${callTypeArgs.head}; cannot take constValue"
689+
return ref(defn.Predef_undefined).withSpan(call.span).withType(ErrorType(msg))
690+
else
691+
return constVal
689692
}
690693
else if (inlinedMethod == defn.Compiletime_constValueOpt) {
691694
val constVal = tryConstValue

tests/neg/i11985.scala

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import compiletime._
2+
import compiletime.ops.int._
3+
4+
object Test {
5+
type TupleTypeIndex[T <: Tuple, C] <: Int = T match {
6+
case C *: t => 0
7+
case h *: t => S[TupleTypeIndex[t, C]]
8+
}
9+
10+
trait TupleExtractor[TT <: Tuple, C] {
11+
def get(t: TT): C
12+
}
13+
14+
given [T <: Tuple, C, EV <: TupleTypeIndex[T, C]]: TupleExtractor[T, C] with {
15+
def get(t: T): C = t.toArray.apply(toIntC[TupleTypeIndex[T, C]]).asInstanceOf[C] // error
16+
}
17+
18+
19+
transparent inline def toIntC[N <: Int]: Int =
20+
inline constValue[N] match
21+
case 0 => 0
22+
case _: S[n1] => 1 + toIntC[n1]
23+
24+
}

0 commit comments

Comments
 (0)