Skip to content

fix(cddl): preserve float literals so (0.0..1.0) is distinct from (0..1) - #77

Merged
christian-bromann merged 1 commit into
webdriverio:mainfrom
titusfortner:c/cddl-float-literal-bug-5ae049
Jul 30, 2026
Merged

fix(cddl): preserve float literals so (0.0..1.0) is distinct from (0..1)#77
christian-bromann merged 1 commit into
webdriverio:mainfrom
titusfortner:c/cddl-float-literal-bug-5ae049

Conversation

@titusfortner

Copy link
Copy Markdown
Contributor

What does this PR do?

  • Numeric literal nodes in the parsed AST now record whether the value was written as a float, via a new IsFloat: true marker on float literals.
  • A floating-point range like (0.0..1.0) is now distinguishable from an integer range (0..1). Previously both produced byte-for-byte identical nodes (Min.Value: 0, Max.Value: 1), because whole-valued floats such as 1.0 collapsed to plain integers — the lexer's FLOAT vs NUMBER distinction was lost at AST construction.
  • Consumers walking the AST (validators, code generators, downstream tooling) can now tell 1.0 from 1 without re-lexing.

Implementation Notes

  • The marker is only present on float literals (IsFloat?: boolean, absent for integers), so the change is purely additive — existing integer literal nodes are unchanged and no consumer relying on the current shape breaks.
  • Range Min/Max inherit the marker for free, since both are built from these literal nodes.
  • Scope kept to the parser (the shared root cause). The bundled CDDL→language generators (cddl2java, cddl2py, cddl2swift, cddl2kotlin) emit an integer type for float ranges and can now consult IsFloat to fix that — tracked separately. cddl2ts needs no change (TypeScript has a single number type).
  • Snapshot updates are limited to genuine float literals already present in fixtures (e.g. 0.1, 1.5) gaining the new marker.

@christian-bromann christian-bromann left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@christian-bromann
christian-bromann merged commit 8c3dc77 into webdriverio:main Jul 30, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants