Commit 886727c
fix ICE in serializeValueAsJson (#9804)
- [x] Add test for known scalar constructors as ModelProperty default
values in openapi3
- [x] Fix serializeValueAsJson to return undefined for unrecognized
scalar constructors
- [x] Remove inadvertent csharp emitter file changes (reverted to pre-PR
state)
<!-- START COPILOT ORIGINAL PROMPT -->
<details>
<summary>Original prompt</summary>
>
> ----
>
> *This section details on the original issue you should resolve*
>
> <issue_title>[core] ICE in serializeValueAsJson</issue_title>
> <issue_description>### Describe the bug
>
> The core library throws an uncaught Error on a custom scalar
initializer with no arguments in `serializeValueAsJson`. The Error is
provoked by the OpenAPI3 emitter (as well as the JSON Schema emitter)
and bubbles back up to the emitter entrypoint where it triggers an ICE.
>
> The logic attempts to use the first argument of the initializer, which
isn't reliable. That logic works for "cast-like" scalar values (e.g.
`uuid("...")`), but not for initializers (e.g. `uuid.random() // no
first argument!`).
>
> ### Reproduction
>
> ```tsp
> scalar S {
> init i();
> }
>
> model M { p: S = S.i(); }
> ```
>
>
https://typespec.io/playground/?e=%40typespec%2Fopenapi3&c=c2NhbGFyIFMgewogIGluaXQgaSgpOwp9Cgptb2RlbCBNIHsgcDogUyA9IFMuxBsgfQ%3D%3D&options=%7B%7D&vs=%7B%7D
>
> However, if you provide a first argument, this is enough to quell the
ICE but the emit is still wrong:
>
> ```tsp
> scalar S {
> init i(s: string);
> }
>
> // Default value renders as "foo", which is wrong.
> model M { p: S = S.i("foo") }
> ```
>
>
https://typespec.io/playground/?e=%40typespec%2Fopenapi3&c=c2NhbGFyIFMgewogIGluaXQgaShzOiBzdHJpbmcpOwp9Cgptb2RlbCBNIHsgcDogUyA9IFMuaSgiZm9vIik7IH0%3D&options=%7B%7D&vs=%7B%7D
>
> ### Checklist
>
> - [x] Follow our [Code of
Conduct](https://github.com/microsoft/typespec/blob/main/CODE_OF_CONDUCT.md)
> - [x] Check that there isn't already an issue that request the same
bug to avoid creating a duplicate.
> - [x] Check that this is a concrete bug. For Q&A open a [GitHub
Discussion](https://github.com/Microsoft/typespec/discussions).
> - [x] The provided reproduction is a [minimal reproducible
example](https://stackoverflow.com/help/minimal-reproducible-example) of
the bug.</issue_description>
>
> <agent_instructions>Instead we should drop the result if we don't
recognize the constructor</agent_instructions>
>
> ## Comments on the Issue (you are @copilot in this section)
>
> <comments>
> <comment_new><author>@timotheeguerin</author><body>
> Drop the result like we do with `now()` if we can't resolve the scalar
constructor</body></comment_new>
> </comments>
>
</details>
<!-- START COPILOT CODING AGENT SUFFIX -->
- Fixes #9781
<!-- START COPILOT CODING AGENT TIPS -->
---
🔒 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.](https://gh.io/cca-advanced-security)
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
Co-authored-by: Timothee Guerin <tiguerin@microsoft.com>1 parent 6ca470a commit 886727c
File tree
4 files changed
+62
-3
lines changed- .chronus/changes
- packages
- compiler
- src/lib
- test/decorators
- openapi3/test
4 files changed
+62
-3
lines changedLines changed: 9 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
229 | 229 | | |
230 | 230 | | |
231 | 231 | | |
232 | | - | |
| 232 | + | |
233 | 233 | | |
234 | 234 | | |
235 | 235 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
133 | 155 | | |
134 | 156 | | |
135 | 157 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
262 | 262 | | |
263 | 263 | | |
264 | 264 | | |
265 | | - | |
| 265 | + | |
266 | 266 | | |
267 | 267 | | |
268 | 268 | | |
| |||
272 | 272 | | |
273 | 273 | | |
274 | 274 | | |
275 | | - | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
276 | 304 | | |
277 | 305 | | |
278 | 306 | | |
| |||
0 commit comments