feat: add record spread syntax { ...base, field: val }
Adds spread operator for records, allowing concise record updates:
let p2 = { ...p, x: 5.0 }
Changes across the full pipeline:
- Lexer: new DotDotDot (...) token
- AST: optional spread field on Record variant
- Parser: detect ... at start of record expression
- Typechecker: merge spread record fields with explicit overrides
- Interpreter: evaluate spread, overlay explicit fields
- JS backend: emit native JS spread syntax
- C backend: copy spread into temp, assign overrides
- Formatter, linter, LSP, symbol table: propagate spread
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -688,15 +688,17 @@ impl Formatter {
|
||||
.join(", ")
|
||||
)
|
||||
}
|
||||
Expr::Record { fields, .. } => {
|
||||
format!(
|
||||
"{{ {} }}",
|
||||
fields
|
||||
.iter()
|
||||
.map(|(name, val)| format!("{}: {}", name.name, self.format_expr(val)))
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ")
|
||||
)
|
||||
Expr::Record {
|
||||
spread, fields, ..
|
||||
} => {
|
||||
let mut parts = Vec::new();
|
||||
if let Some(spread_expr) = spread {
|
||||
parts.push(format!("...{}", self.format_expr(spread_expr)));
|
||||
}
|
||||
for (name, val) in fields {
|
||||
parts.push(format!("{}: {}", name.name, self.format_expr(val)));
|
||||
}
|
||||
format!("{{ {} }}", parts.join(", "))
|
||||
}
|
||||
Expr::EffectOp { effect, operation, args, .. } => {
|
||||
format!(
|
||||
|
||||
Reference in New Issue
Block a user