Skip to content

Cannot match on Type of opaque type with type variable #15470

@prolativ

Description

@prolativ

Compiler version

3.1.3 and earlier ones

Minimized code

Macro.scala

//> using scala "3.1.3"

import scala.quoted.*

object OpaqueScope:
  opaque type MyInt[A] = Int

export OpaqueScope.MyInt

inline def foo() = ${ fooImpl }

def fooImpl(using Quotes) =
  Type.of[MyInt[String]] match
    case '[MyInt[a]] => '{}

MacroTest.scala

def bar = foo()

Output

[error] ./MacroTest.scala:1:11: Exception occurred while executing macro expansion.
[error] scala.MatchError: Type.of[...] (of class scala.quoted.runtime.impl.TypeImpl)
[error]         at Macro$package$.fooImpl(Macro.scala:14)
[error] 
[error] def bar = foo()
[error]           ^^^

Expectation

The pattern match should succeed, just as it does if one of the changes below is made:

  • MyInt is declared as a trait or a non-opaque type alias instead of an opaque type alias
  • the concrete type '[MyInt[String]] is used in the match pattern instead of '[MyInt[a]] with a type variable

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions