Skip to content

Fix incorrect #any capability for type parameters with union constraints#5337

Open
SeanTAllen wants to merge 1 commit into
mainfrom
fix-issue-2674-union-constraint-cap
Open

Fix incorrect #any capability for type parameters with union constraints#5337
SeanTAllen wants to merge 1 commit into
mainfrom
fix-issue-2674-union-constraint-cap

Conversation

@SeanTAllen
Copy link
Copy Markdown
Member

@SeanTAllen SeanTAllen commented May 16, 2026

The cap_union_constraint function in src/libponyc/type/typeparam.c was missing many entries. Pairs of caps whose atomic members all lived in #alias fell through to #any instead of returning #alias. The most visible symptom was the original bug from #2674: a type parameter constrained by (_OutAsync tag | _OutSync ref) got cap #any and produced "argument type is O #any !" when the value was passed to a helper that needed re-aliasing.

The fix completes the cap-set table so the function uniformly returns the smallest cap-set containing both inputs. The TK_VAL switch arm was also missing its trailing break; — harmless pre-fix because every b value reachable through the fall-through was also handled in the TK_VAL arm, but the fix needs the break because TK_VAL now has a TK_CAP_ALIAS case that fall-through would otherwise clobber.

The accompanying full-program regression test declares 26 generic primitives, each exercising one switch-arm + subcase pair, so a future regression of any one pair fails to type-check. Counterfactually verified: reverting the table additions produces 21 compile errors against the test.

The two adjacent concerns from the issue (forbidding reification with the literal union type; iftype completeness checks) are language-design RFC material, not bug fixes, and are out of scope here.

Closes #2674

@SeanTAllen SeanTAllen added the changelog - fixed Automatically add "Fixed" CHANGELOG entry on merge label May 16, 2026
@ponylang-main ponylang-main added the discuss during sync Should be discussed during an upcoming sync label May 16, 2026
cap_union_constraint was missing many entries; pairs whose atomic members
all live in #alias fell through to #any instead of returning #alias. The
TK_VAL switch arm was also missing its trailing break; though the
fall-through into TK_BOX happened to be harmless pre-fix.

Closes #2674
@SeanTAllen SeanTAllen force-pushed the fix-issue-2674-union-constraint-cap branch from 1b5170d to e9d6359 Compare May 22, 2026 18:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog - fixed Automatically add "Fixed" CHANGELOG entry on merge discuss during sync Should be discussed during an upcoming sync

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Type parameter with union type constraint treats constraint cap as #any.

2 participants