Skip to content

fix(types): validate symbolic parameter defaults#565

Merged
nahime0 merged 2 commits into
mainfrom
fix/enum-case-default-validation
Jul 19, 2026
Merged

fix(types): validate symbolic parameter defaults#565
nahime0 merged 2 commits into
mainfrom
fix/enum-case-default-validation

Conversation

@nahime0

@nahime0 nahime0 commented Jul 18, 2026

Copy link
Copy Markdown
Member

Summary

This replaces the approach proposed in #468 with post-schema semantic validation for symbolic parameter defaults.

infer_expr_type_syntactic classifies every ScopedConstantAccess as Str. Accepting Enum::Member solely because the receiver name matches the declared object type would therefore bypass validation and also accept missing enum cases or scalar class constants.

This PR instead:

  • defers direct scoped-constant parameter defaults while class-like schemas are being built;
  • resolves them semantically after class, interface, and enum metadata is complete, reusing infer_scoped_constant_access;
  • distinguishes enum cases, class constants, and undefined symbols;
  • preserves the declaring-class context for named, self::, static::, and parent:: receivers;
  • covers unused functions, methods and constructors, constructor promotion, and closures;
  • keeps plain property enum defaults out of scope because their EIR lowering is still incomplete.

Testing

  • cargo build
  • cargo test --test codegen_tests accepts_enum_case
  • cargo test --test codegen_tests enum_case_default
  • cargo test --test error_tests enum_case_parameter_default_rejects_missing_case
  • cargo test --test error_tests object_parameter_default_rejects_scalar_class_constant
  • cargo test --test error_tests plain_property_enum_case_default_remains_unsupported
  • cargo test --test codegen_tests interface_promoted_property_accepts_object_default
  • cargo test --test error_tests promoted_property_rejects_incompatible_object_default
  • git diff --check

Related: #468

@github-actions github-actions Bot added area:types Touches type checking, inference, or compatibility. size:s Small pull request. type:fix Corrects broken or incompatible behavior. area:codegen Touches target-aware assembly or backend lowering. size:m Medium-sized pull request. and removed size:s Small pull request. labels Jul 18, 2026
@nahime0
nahime0 force-pushed the fix/enum-case-default-validation branch from 840194a to c44b638 Compare July 19, 2026 09:09
@nahime0
nahime0 merged commit 9cd38c6 into main Jul 19, 2026
113 checks passed
@nahime0
nahime0 deleted the fix/enum-case-default-validation branch July 19, 2026 10:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:codegen Touches target-aware assembly or backend lowering. area:types Touches type checking, inference, or compatibility. size:m Medium-sized pull request. type:fix Corrects broken or incompatible behavior.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant