Skip to content

fix(types): honor generic variance for same-class assignments - #9010

Open
chess10kp wants to merge 6 commits into
jaseci-labs:mainfrom
chess10kp:fix/8550-generic-variance
Open

fix(types): honor generic variance for same-class assignments#9010
chess10kp wants to merge 6 commits into
jaseci-labs:mainfrom
chess10kp:fix/8550-generic-variance

Conversation

@chess10kp

Copy link
Copy Markdown
Collaborator

Closes #8550

Also fixes the same mutable-container covariance hole reported in #8580.

Summary

TypeEvaluator._assign_class already applied declared variance when comparing a generic subclass with a generic base, but the same-class path always used one-way assign_type. This accepted list[Dog] as list[Animal] even though list is invariant.

This patch centralizes generic argument comparison and applies:

  • covariant: source argument assigns to destination argument
  • contravariant: destination argument assigns to source argument
  • invariant: both directions must assign

The helper is used by both same-class and generic-base comparisons. Unknown destination arguments remain open for inferred tuple filters.

Verification

  • Minimal repro before the fix: jac check accepted list[Dog] passed to list[Animal].
  • After the fix: the repro reports E1053: Cannot assign list[Dog] to parameter 'xs' of type list[Animal].
  • Targeted test: cd jac && jac test tests/compiler/passes/test_checker_bugs.jac --test_name bug_8550_same_class_generic_variance -x (1 passed).

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.

[Bug] Generic list covariance accepted: list[Dog] passes where list[Animal] expected (unsound)

1 participant