Skip to content

feat: compile-time constant expressions in type declarations #201

Description

@ganehag

Problem

Range bounds and default values in type declarations must be literals. Named constants cannot be used as bounds, which limits expressiveness and makes shared domain constants fragile (a change to the constant does not propagate to type declarations).

const MIN_PORT = 1
const MAX_PORT = 65535

type Port int range MIN_PORT..MAX_PORT   // currently rejected — bounds must be literals
type PrivilegedPort int range MIN_PORT..1023

Expected behaviour

Any const expression resolvable at compile time should be usable as a range bound, cycle bound, or default value in a type declaration.

Scope

  • Named const bindings defined earlier in the same file or imported from a module
  • Simple arithmetic over constants: MAX_PORT div 2
  • Not: arbitrary function calls, runtime values

Notes

  • The compiler already evaluates constant-pool entries at compile time. This is an extension of that mechanism to the type declaration path.
  • Affects: range lo..hi, cycle lo..hi, default val in named type declarations.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Low priorityarea:compilerLexer, parser, compilerenhancementNew feature or request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions