Closed
Description
Summary
The spec now allows const NAME = EXPR when the initializer determines an unambiguous type. const NAME: TYPE = EXPR remains available for API clarity and disambiguation, and public exported constants must keep an explicit type annotation.
Current behavior
The parser still requires a type annotation for every const declaration.
Observed with ./out/bin/with -e:
./out/bin/with -e 'const X = 1; let y = X'
# error: const declaration requires a type annotation
./out/bin/with -e 'const X: i32 = 1; let y = X'
# acceptedPublic untyped constants should remain rejected, but the diagnostic should be the narrower rule:
pub const X = 1
// error: public const declarations require an explicit type annotation
Suspected root cause
src/Parser.w rejects missing : in both const parser paths:
parse_const_decl(module/global declarations)parse_const_binding(local bindings)
Both currently emit const declaration requires a type annotation before sema can infer from the initializer.
Expected behavior
- Accept private/module
const NAME = EXPRwhen the initializer determines a concrete type using normal inference and default literal rules. - Accept local
const NAME = EXPRunder the same rule. - Keep
const NAME: TYPE = EXPRworking. - Reject public/exported
pub const NAME = EXPRwith a diagnostic that says public constants require explicit type annotations for API stability. - Reject untyped const declarations whose initializer cannot determine a concrete type.
- Add behavior and compile-error coverage.
Spec references
docs/with-specification.md§9.1bconstDeclarationsdocs/requirements.md9.1.3.2and9.1.3.3
Metadata
Metadata
Assignees
Labels
No labels
Activity