fix(compiler): avoid ICE in serializeValueAsJson for no-argument scalar constructors#9804
fix(compiler): avoid ICE in serializeValueAsJson for no-argument scalar constructors#9804
Conversation
…n serializeValueAsJson Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
|
@copilot This fix is overbroad, causing 3 tests that use known scalars to fail. Please ensure that all tests are passing. Also, please add a test that checks the openapi3 serialization of a default value for a model property, similar to the one shown in the repro. |
…reserve args[0] behavior Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
Fixed in e2f42d9. The previous fix was too broad — it dropped The correct fix only returns Also added the openapi3 test that checks Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
serializeScalarValueAsJsonwould crash with an ICE when a custom scalar value used a no-argument initializer (e.g.S.i()), because the code unconditionally accessedvalue.value.args[0]which isundefinedin that case.Changes
packages/compiler/src/lib/examples.ts: WhenresolveKnownScalarreturnsundefined(scalar is not a known built-in), only returnundefinedifargs[0]is missing (the no-arg case that caused the ICE). Whenargs[0]is present, the original behavior of using it as the serialized value is preserved — this is intentional for cast-like scalar constructors (e.g.shortName.name("Shorty")correctly serializes as"Shorty").packages/compiler/test/decorators/examples.test.ts: Added regression tests — the no-argument initializer case (test.i()) returnsundefined, and the with-argument initializer case (test.name("Shorty")) serializes the first argument.packages/openapi3/test/models.test.ts: Added a test verifying that a model property default using a no-argument scalar initializer (the exact repro from the issue) does not crash and produces no default value in the emitted schema.Reproduction
Original prompt
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.