Skip to content

Conversation

@KotlinIsland
Copy link
Contributor

i can't update the results on my machine, sorry!

@KotlinIsland KotlinIsland changed the title (🎁) conformance: check for variance on constrained types (🎁) conformance: check for variance on constrained type variables May 28, 2025
Copy link
Collaborator

@erictraut erictraut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this proposed test is correct. I also can't find where it's specified in the typing spec.

# reveal_type(concat(m, a))
# reveal_type(concat(a, m))

BadConstraint3 = TypeVar("BadConstraint3", str, int, covariant=True) # E: constraints can't have variance
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't find where in the typing spec this is specified. I'm also not sure why it would be the case that value-constrained type variables can't be covariant.

In any case, all conformance tests should derive from the spec itself. You'll see that in most of the tests, the exact text of the spec is quoted to motivate each of the tests.

@JelleZijlstra
Copy link
Member

Note that variance is meaningful on constrained type variables if one constraint is assignable to the other. (Given a class X[T: (int, bool)], X[bool] is assignable to X[int] only if T is covariant.)

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