Commit 2b705fa
Compute union switch-arm pattern type from the case symbol in the parser
The emitter previously derived the C# `value switch` pattern type by
stripping a trailing `?` character from the case's fully-qualified name —
a stringly-typed shortcut that relied on the `SymbolDisplayFormat` spelling
of `Nullable<T>` always ending in `?` and would silently produce a
malformed identifier for any FQN that did not. Reviewer feedback flagged
this as unsafe.
Move the decision to the parser, where the actual `ITypeSymbol` is in
scope. `UnionCaseSpec` gains a `PatternType : TypeRef` property which is
* `Nullable<T>.TypeArguments[0]` (the underlying `T`) for value-type
`Nullable<T>` cases, and
* `CaseType` for everything else.
The emitter just reads `caseSpec.PatternType.FullyQualifiedName`; the
`GetPatternTypeFullyQualifiedName` helper is deleted. Snapshot output is
byte-identical (`StringOrIntUnion` baseline still matches), all four test
suites stay at the same counts.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent 2ea38bb commit 2b705fa
3 files changed
Lines changed: 26 additions & 23 deletions
File tree
- src/libraries/System.Text.Json/gen
- Model
Lines changed: 2 additions & 22 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
677 | 677 | | |
678 | 678 | | |
679 | 679 | | |
680 | | - | |
| 680 | + | |
681 | 681 | | |
682 | 682 | | |
683 | 683 | | |
| |||
751 | 751 | | |
752 | 752 | | |
753 | 753 | | |
754 | | - | |
| 754 | + | |
755 | 755 | | |
756 | 756 | | |
757 | 757 | | |
| |||
784 | 784 | | |
785 | 785 | | |
786 | 786 | | |
787 | | - | |
788 | | - | |
789 | | - | |
790 | | - | |
791 | | - | |
792 | | - | |
793 | | - | |
794 | | - | |
795 | | - | |
796 | | - | |
797 | | - | |
798 | | - | |
799 | | - | |
800 | | - | |
801 | | - | |
802 | | - | |
803 | | - | |
804 | | - | |
805 | | - | |
806 | | - | |
807 | 787 | | |
808 | 788 | | |
809 | 789 | | |
| |||
Lines changed: 13 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
749 | 749 | | |
750 | 750 | | |
751 | 751 | | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
752 | 763 | | |
753 | 764 | | |
754 | | - | |
| 765 | + | |
| 766 | + | |
755 | 767 | | |
756 | 768 | | |
757 | 769 | | |
| |||
Lines changed: 11 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
21 | 32 | | |
22 | 33 | | |
23 | 34 | | |
| |||
0 commit comments