feat(lang): block value requires no trailing ; (Rust-style)
A block's value is now its last statement ONLY when that statement is a trailing expression with no `;`. A trailing `;` discards the value, leaving the block void. This makes value-vs-statement explicit and lets the compiler reject "this block was supposed to produce a value". Compiler: - Parser records `Block.produces_value` (last stmt is a no-`;` trailing expression) + `Block.discarded_semi` (the `;` that discarded a value), via `expectSemicolonAfter`. A trailing expression before `}` may now omit its `;` (previously a parse error). Match-arm and else-arm bodies are built value-producing regardless of the arm `;` (arms are exempt — the `;` is an arm terminator). - Lowering: `lowerBlockValue` / the block-expr path / `inferExprType` respect `produces_value`. A value-position block that discards its value is a hard error (`lowerValueBody` for function bodies; the value-context `.block` path for if/else branches, `catch` bodies, value bindings, match arms). Pure-failable `-> !` bodies (value rides the error channel) and a value-if whose branches are void are handled without false errors. - `defer`/`onfail` cleanup bodies lower as statements (void), so a trailing `;` there is fine. Migration (behavior-preserving — output unchanged): - stdlib + ~210 examples: dropped the trailing `;` on value-position last expressions. `format` now ends with an explicit `#insert "return result;"` (it relied on `#insert`-as-block-value, which `;` discards). - Two `main :: () -> s32` examples that relied on the old silent default-return got an explicit trailing `0`. - Rejection snapshots 0412 / 1013 regenerated (their quoted source lines lost a `;`); the diagnostics themselves are unchanged. Docs/tests: specs.md "Block values" section; examples 0040 (rules) + 0041 (rejection); 3 parser unit tests. Filed issue 0066 (pre-existing match-arm negated-literal phi-width quirk, surfaced not caused here). Gates: zig build, zig build test, run_examples.sh -> 343 passed, cross_compile.sh -> 7 passed (also refreshed its stale example names).
This commit is contained in:
@@ -81,7 +81,7 @@ dock_zone_to_alignment :: (zone: DockZone) -> ?Alignment {
|
||||
}
|
||||
|
||||
dock_zone_should_fill :: (zone: DockZone) -> bool {
|
||||
zone == .fill;
|
||||
zone == .fill
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
@@ -169,7 +169,7 @@ DockInteraction :: struct {
|
||||
|
||||
get_animated_size :: (self: *DockInteraction, index: s64) -> Size {
|
||||
if index >= self.child_count { return Size.zero(); }
|
||||
(@self.anim_sizes.items[index]).current;
|
||||
(@self.anim_sizes.items[index]).current
|
||||
}
|
||||
|
||||
tick_animations :: (self: *DockInteraction, dt: f32) {
|
||||
@@ -184,7 +184,7 @@ DockInteraction :: struct {
|
||||
get_hovered_dock_zone :: (self: *DockInteraction) -> ?DockZone {
|
||||
if self.hovered_zone < 0 { return null; }
|
||||
// Map ordinal back to DockZone
|
||||
cast(DockZone) self.hovered_zone;
|
||||
cast(DockZone) self.hovered_zone
|
||||
}
|
||||
|
||||
set_hovered_dock_zone :: (self: *DockInteraction, zone: ?DockZone) {
|
||||
@@ -242,7 +242,7 @@ find_hovered_zone :: (bounds: Frame, pos: Point, hint_size: f32, enable_corners:
|
||||
if expanded.contains(pos) { return zone; }
|
||||
i += 1;
|
||||
}
|
||||
null;
|
||||
null
|
||||
}
|
||||
|
||||
calculate_origin :: (bounds: Frame, child_size: Size, alignment: Alignment) -> Point {
|
||||
@@ -262,7 +262,7 @@ calculate_origin :: (bounds: Frame, child_size: Size, alignment: Alignment) -> P
|
||||
y = bounds.origin.y + bounds.size.height - child_size.height;
|
||||
}
|
||||
|
||||
Point.{ x = x, y = y };
|
||||
Point.{ x = x, y = y }
|
||||
}
|
||||
|
||||
get_size_proposal_for_alignment :: (alignment: Alignment, bounds_size: Size, is_fill: bool) -> ProposedSize {
|
||||
@@ -280,7 +280,7 @@ get_size_proposal_for_alignment :: (alignment: Alignment, bounds_size: Size, is_
|
||||
}
|
||||
}
|
||||
// Center or corners: natural size
|
||||
ProposedSize.flexible();
|
||||
ProposedSize.flexible()
|
||||
}
|
||||
|
||||
get_final_size_for_alignment :: (alignment: Alignment, child_size: Size, bounds_size: Size, is_fill: bool) -> Size {
|
||||
@@ -299,7 +299,7 @@ get_final_size_for_alignment :: (alignment: Alignment, child_size: Size, bounds_
|
||||
}
|
||||
}
|
||||
// Center or corners: natural size
|
||||
child_size;
|
||||
child_size
|
||||
}
|
||||
|
||||
draw_zone_indicator :: (ctx: *RenderContext, frame: Frame, zone: DockZone, color: Color) {
|
||||
@@ -385,15 +385,15 @@ DockPanel :: struct {
|
||||
header_height = DockPanel.DEFAULT_HEADER_H,
|
||||
dock_interaction = null, // set by Dock.add_panel
|
||||
panel_index = 0
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl View for DockPanel {
|
||||
size_that_fits :: (self: *DockPanel, proposal: ProposedSize) -> Size {
|
||||
content_size := self.child.view.size_that_fits(ProposedSize.{ width = proposal.width, height = null });
|
||||
w := if pw := proposal.width { min(content_size.width, pw); } else { content_size.width; };
|
||||
Size.{ width = w, height = content_size.height + self.header_height };
|
||||
w := if pw := proposal.width { min(content_size.width, pw) } else { content_size.width };
|
||||
Size.{ width = w, height = content_size.height + self.header_height }
|
||||
}
|
||||
|
||||
layout :: (self: *DockPanel, bounds: Frame) {
|
||||
@@ -446,7 +446,7 @@ impl View for DockPanel {
|
||||
}
|
||||
|
||||
// Forward to child content
|
||||
self.child.view.handle_event(event, self.child.computed_frame);
|
||||
self.child.view.handle_event(event, self.child.computed_frame)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -484,7 +484,7 @@ Dock :: struct {
|
||||
d.preview_color = Color.rgba(77, 153, 255, 64);
|
||||
d.enable_corners = true;
|
||||
d.on_dock = null;
|
||||
d;
|
||||
d
|
||||
}
|
||||
|
||||
add_panel :: (self: *Dock, panel: DockPanel) {
|
||||
@@ -508,7 +508,7 @@ impl View for Dock {
|
||||
Size.{
|
||||
width = proposal.width ?? 800.0,
|
||||
height = proposal.height ?? 600.0
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
layout :: (self: *Dock, bounds: Frame) {
|
||||
@@ -687,6 +687,6 @@ impl View for Dock {
|
||||
}
|
||||
i -= 1;
|
||||
}
|
||||
false;
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user