Skip to content

fix: support variance for type parameters of opaque types in Scala 3 (Issue #548)#578

Open
Erichhhhhcat wants to merge 1 commit intozio:developfrom
Erichhhhhcat:develop
Open

fix: support variance for type parameters of opaque types in Scala 3 (Issue #548)#578
Erichhhhhcat wants to merge 1 commit intozio:developfrom
Erichhhhhcat:develop

Conversation

@Erichhhhhcat
Copy link

Summary

Fixes issue #548 - Scala 3: support variance reading for opaque types

Problem

For opaque type aliases in Scala 3, declaredTypes returns an empty list because the type parameters are not 'declared' in the traditional sense. This caused variance detection to fail:

object x {
  opaque type T[+X] = X
}
// Expected: x.T[+Int] (covariant)
// Actual: x.T[Int] (invariant)

Solution

Added a fallback to use typeSymbol.typeParams to extract variance information when declaredTypes is empty and the symbol is an opaque alias.

if (symbolVariances.isEmpty && tycon.typeSymbol.isOpaqueAlias) {
  symbolVariances = tycon.typeSymbol.typeParams.collect {
    case s if s.isTypeParam => extractVariance(s)
  }
}

Testing

This fix enables correct variance detection for opaque types in Scala 3.

Fixes issue zio#548 - Scala 3: support variance reading for opaque types

For opaque type aliases, declaredTypes returns an empty list because
the type parameters are not 'declared' in the traditional sense. This
fix adds a fallback to use typeSymbol.typeParams to extract variance
information for opaque types.
@CLAassistant
Copy link

CLAassistant commented Feb 23, 2026

CLA assistant check
All committers have signed the CLA.

@neko-kai
Copy link
Member

@Erichhhhhcat Hi, thanks for your contribution! 🙏 Could you please add a test case to scala-3 specific LightTypeTagTest.scala demonstrating the fix?

Erichhhhhcat added a commit to Erichhhhhcat/claude-agent-framework that referenced this pull request Feb 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants