Skip to content

Add type contracts to named expression parameters #998

Description

@Seddryck

Allow explicit parameters to declare Expressif type descriptors, including parameters with defaults.

%define normalize-name = trim | upper;
%define short-name(length -> :integer = 3) =
    &normalize-name | first-chars(@length);

Acceptance criteria:

  • Parse name -> :type, optionally followed by = default; retain untyped declarations.
  • Reuse the canonical type descriptors and supported conversions used by coerce. :integer and :text remain descriptors, not new type names specific to definitions.
  • For coercing parameter contracts, convert the supplied/default value before binding the local parameter. Failed scalar conversion yields #null, which enters the body as a normal value; it neither triggers the default nor skips the body.
  • Preserve the distinction between recoverable conversion failure and structural/unsupported-contract errors. Do not introduce a universal errors-to-null rule.
  • Validate unknown type descriptors and unsupported contracts during binding where possible; make supported target types explicit.
  • Preserve existing coerce(:type) and is-type(:type) behavior.
  • Test successful conversion, already compatible values, failed conversion, explicit null, typed defaults, unknown types, and propagation into the body.
  • Document that a coercing annotation is not a non-null guarantee. Strict contracts and nullable-type syntax are outside this stage.

Stage 5 of 8. Depends on #997.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions