Skip to content

Inline match issue with separate compilation #6157

Closed
@milessabin

Description

@milessabin

The following compiles correctly as a single source file,

import scala.compiletime._

object Utils {
  type Id[t] = t

  inline def summonAllValues[T] <: T = inline erasedValue[Id[T]] match {
    case _: Unit => ()
    case _: (a, b) => (constValue[a], summonAllValues[b])
  }
}

import Utils._

object Foo {
  type Labels = ("i", ("s", ("b", Unit)))
}

object Test extends App {
  val labels = summonAllValues[Foo.Labels]
}

However, if Utils is split off to a separate source file and compiled first,

import scala.compiletime._

object Utils {
  type Id[t] = t

  inline def summonAllValues[T] <: T = inline erasedValue[Id[T]] match {
    case _: Unit => ()
    case _: (a, b) => (constValue[a], summonAllValues[b])
  }
}

with the following second,

import Utils._

object Foo {
  type Labels = ("i", ("s", ("b", Unit)))
}

object Test extends App {
  val labels = summonAllValues[Foo.Labels]
}

then the latter fails with,

-- Error: tests/pos/inline-match-separate/inline-match-separate_1.scala:6:65 ---
6 |  inline def summonAllValues[T] <: T = inline erasedValue[Id[T]] match {
  |                                       ^
  |cannot reduce inline match with
  | scrutinee:  compiletime.erasedValue[Utils.Id[Foo.Labels]] : Utils.Id[Foo.Labels]
  | patterns :  case _:Unit
  |             case _:Tuple2[a @ _, b @ _]
  | This location is in code that was inlined at inline-match-separate_2.scala:8
7 |    case _: Unit => ()
8 |    case _: (a, b) => (constValue[a], summonAllValues[b])
9 |  }
one error found

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions