Skip to content

Opaque types do not work with match types #17211

Closed
@chuwy

Description

@chuwy

Compiler version

3.3.0-RC3 and 3.2.2

Minimized code

import scala.compiletime.constValue

type IsInt[A] = A match
  case Int => true
  case _   => false

constValue[IsInt[Int]]     // val res2: Boolean = true; works as expected                                                                                                                        
constValue[IsInt[String]]  // val res3: Boolean = false; works as expected

object Foo:
  opaque type Foo = Int

constValue[IsInt[Foo.Foo]]    // compile-time error

Output

1 |constValue[IsInt[Foo.Foo]]
  |^^^^^^^^^^^^^^^^^^^^^^^^^^
  |not a constant type: IsInt[rs$line$2#Foo.Foo]; cannot take constValue

Expectation

I don't know if it should have been true or false (probably false), but compilation error certainly wasn't expected. My expectation was that an opaque type T is treated as any other T >: Nothing <: Any.

Metadata

Metadata

Assignees

No one assigned

    Labels

    SpreeSuitable for a future Spreearea:reportingError reporting including formatting, implicit suggestions, etcitype:enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions