Skip to content

cap_isect_constraint returns TK_CAP_ANY for unhandled capability pairs #4988

@SeanTAllen

Description

@SeanTAllen

cap_isect_constraint in src/libponyc/type/typeparam.c computes the effective capability when a type parameter is constrained by an intersection of types. When it encounters a pair of concrete capabilities that aren't handled by any switch case (e.g., TK_REF and TK_VAL), it falls through to the default return on line 290 and returns TK_CAP_ANY.

This is incorrect. The intersection of {ref} and {val} is empty — no capability is in both sets. The function should return an error/empty indicator, not the universal set.

Example: cap_isect_constraint(TK_REF, TK_VAL) returns TK_CAP_ANY instead of indicating an empty intersection.

This doesn't affect soundness because every caller of cap_isect_constraint (via cap_from_constrainttypeparam_set_cap) feeds the result into further validation through full subtyping checks. But it means the compiler accepts type arguments with uninhabited intersection types instead of rejecting them with a clear error.

Found during investigation of intersection type interactions with generic constraints for #4978.

Metadata

Metadata

Assignees

Labels

discuss during syncShould be discussed during an upcoming sync

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions