Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/Inliner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -684,8 +684,11 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
if (callTypeArgs.length == 1)
if (inlinedMethod == defn.Compiletime_constValue) {
val constVal = tryConstValue
if (!constVal.isEmpty) return constVal
report.error(em"not a constant type: ${callTypeArgs.head}; cannot take constValue", call.srcPos)
if constVal.isEmpty then
val msg = em"not a constant type: ${callTypeArgs.head}; cannot take constValue"
return ref(defn.Predef_undefined).withSpan(call.span).withType(ErrorType(msg))
else
return constVal
}
else if (inlinedMethod == defn.Compiletime_constValueOpt) {
val constVal = tryConstValue
Expand Down
24 changes: 24 additions & 0 deletions tests/neg/i11985.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import compiletime._
import compiletime.ops.int._

object Test {
type TupleTypeIndex[T <: Tuple, C] <: Int = T match {
case C *: t => 0
case h *: t => S[TupleTypeIndex[t, C]]
}

trait TupleExtractor[TT <: Tuple, C] {
def get(t: TT): C
}

given [T <: Tuple, C, EV <: TupleTypeIndex[T, C]]: TupleExtractor[T, C] with {
def get(t: T): C = t.toArray.apply(toIntC[TupleTypeIndex[T, C]]).asInstanceOf[C] // error
}


transparent inline def toIntC[N <: Int]: Int =
inline constValue[N] match
case 0 => 0
case _: S[n1] => 1 + toIntC[n1]

}