Repository navigation
fix: turn field default values into correct PHP defaults - #48
Merged
Merged
Conversation
`[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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
[default = ...]baked into a constructor parameter was wrong for several types: inf, -inf and nan becamefalse(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, soclassproducedE::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.