Skip to content

Fix show appends unit suffixes for Float values with units - #69

Merged
ilyakooo0 merged 1 commit into
masterfrom
push-mylqzqrkurvu
Jul 12, 2026
Merged

Fix show appends unit suffixes for Float values with units#69
ilyakooo0 merged 1 commit into
masterfrom
push-mylqzqrkurvu

Conversation

@ilyakooo0

Copy link
Copy Markdown
Owner

Summary

DESIGN.md documents show 42.0<M> should produce "42.0 M", but the runtime printed "42.0". TypeEnv.show_unit_strings was never populated or read — the unit system existed in the type checker and codegen but the runtime had no way to know a Float's unit string.

Fix

  • Codegen registers unit strings at init via knot_register_show_unit (populated from unit inference results)
  • Runtime's show function appends the unit suffix when a Float has a registered unit
  • stripUnit remains the escape hatch for bare-number output

Tests

  • 3 end-to-end tests in regress_show_units.rs: DESIGN examples, computed units (100.0<M> / 4.0<S>"25.0 M/S"), polymorphic case
  • 2 new runtime tests

Verification

cargo test -p knot-runtime
# 147 passed
cargo test -p knot-compiler --test regress_show_units
# 3 passed

@ilyakooo0 ilyakooo0 added the bug Something isn't working label Jul 12, 2026
DESIGN.md documents show 42.0<M> should produce '42.0 M', but the
runtime printed '42.0'. TypeEnv.show_unit_strings was never populated
or read — the unit system existed in the type checker and codegen but
the runtime had no way to know a Float's unit string.

Fix: codegen registers unit strings at init via knot_register_show_unit
(populated from the unit inference results). The runtime's show
function appends the unit suffix when a Float has a registered unit.
stripUnit remains the escape hatch for bare-number output.

3 new end-to-end tests in regress_show_units.rs: DESIGN examples,
computed units (100.0<M> / 4.0<S> -> '25.0 M/S'), polymorphic case.
2 new runtime tests. Full workspace: 1655 passed, 0 failed.
@ilyakooo0
ilyakooo0 force-pushed the push-mylqzqrkurvu branch from 182c30f to 4f901d7 Compare July 12, 2026 00:40
@ilyakooo0
ilyakooo0 merged commit a39ad73 into master Jul 12, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant