zio/izumi-reflect

Scala 3: support variance reading for opaque types

Open

#548 opened on Aug 12, 2025

View on GitHub
 (0 comments) (0 reactions) (0 assignees)Scala (68 forks)github user discovery
buggood first issuehelp wantedscala3

Repository metrics

Stars
 (157 stars)
PR merge metrics
 (PR metrics pending)

Description

Right now izumi-reflect correctly detects variance on Scala 3 for trait/class types:

trait X[+T]
0 -> X[+0]

But not for opaque types, where type variables are assumed invariant:

object x {
  opaque type X[+T] = Any
}
0 -> x::X[0]

That's because we rely on Symbol#declaredTypes method to find out the variances of type parameters of a type. But an opaque type does not "declare" its parameters as members of its definition and therefore declaredTypes List is empty.

We need to find and test some other way to extract that data – perhaps using private compiler APIs if there's no way to extract that data using public API.

Contributor guide