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.
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).
Expected behaviour
Any
constexpression resolvable at compile time should be usable as a range bound, cycle bound, or default value in a type declaration.Scope
constbindings defined earlier in the same file or imported from a moduleMAX_PORT div 2Notes
range lo..hi,cycle lo..hi,default valin named type declarations.