Skip to content

fix: turn field default values into correct PHP defaults - #48

Merged
kafkiansky merged 1 commit into
0.6.xfrom
fix/field-default-values
Nov 22, 2026
Merged

kafkiansky merged 1 commit into
0.6.xfrom
fix/field-default-values

Conversation

@kafkiansky

Copy link
Copy Markdown
Contributor

[default = ...] baked into a constructor parameter was wrong for several types: inf, -inf and nan became false (the class did not compile), uint64 values above PHP_INT_MAX became 0, bytes kept their C escapes as literal text, and an enum default was printed without the escaping its case gets, so class produced E::class.

Defaults are now parsed per type: \INF, -\INF and \NAN for floats, a string argument of \BcMath\Number beyond PHP_INT_MAX, decoded bytes, and the enum member under its generated name (aliases included). A default of a 32-bit float is rounded to float precision, the value the field holds on the wire. A value that is not valid for its type fails with CodeCannotBeGenerated instead of silently becoming 0 or false.

Samples of GeneratedCodeTest may now be closures checking values of the generated code, and NaN compares equal to NaN in round-trips.

`[default = ...]` baked into a constructor parameter was wrong for several
types: inf, -inf and nan became `false` (the class did not compile),
uint64 values above PHP_INT_MAX became 0, bytes kept their C escapes as
literal text, and an enum default was printed without the escaping its
case gets, so `class` produced `E::class`.

Defaults are now parsed per type: \INF, -\INF and \NAN for floats, a
string argument of \BcMath\Number beyond PHP_INT_MAX, decoded bytes, and
the enum member under its generated name (aliases included). A default of
a 32-bit float is rounded to float precision, the value the field holds
on the wire. A value that is not valid for its type fails with
CodeCannotBeGenerated instead of silently becoming 0 or false.

Samples of GeneratedCodeTest may now be closures checking values of the
generated code, and NaN compares equal to NaN in round-trips.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@kafkiansky kafkiansky self-assigned this Nov 22, 2026
@kafkiansky
kafkiansky merged commit 450e361 into 0.6.x Nov 22, 2026
10 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.

1 participant