Fix generated error constructors and constraint attributes using the wrong C# types - #11600
Conversation
Adds handling for Tuple, StringTemplate, EnumMember, ModelProperty, UnionVariant, template parameters and the full Intrinsic set. An unsupported type now reports a diagnostic and falls back to `object` instead of throwing. Also fixes the C# components reporting a TypeScript diagnostic for unsupported scalars, and corrects the C# expressions emitted for the `null` and `never` intrinsics. Adds an `isCSharpValueType` util.
…al_ComponentOverrides The `declaration` descriptor existed but nothing dispatched to it, so an emitter could override how a type is referenced but not how it is declared. The C# `ClassDeclaration`, `Property` and `EnumDeclaration` now render through the override point.
ClassDeclaration takes an explicit property list and extra members, Property takes the full Alloy property prop set plus name/csharpType overrides, EnumDeclaration takes an explicit member list and jsonAttributes, and JsonConverter takes doc, access modifiers, extra members and an explicit csharpType.
…xt.Json symbols Deletes the emitter's own C# keyword table and its re-declaration of the System.Text.Json.Serialization attributes, both of which are provided by @alloy-js/csharp. Namespace segments colliding with BCL type names are still renamed, now via a dedicated getCSharpNamespaceName helper.
…ource of truth The emitter had three disagreeing scalar-to-C# name maps, so error model constructors declared parameters such as DateOnly, Uri and sbyte while the matching properties were DateTime, string and SByte - code that does not compile. NumericConstraintAttribute<T> had the same mismatch.
commit: |
|
All changed packages have been documented.
Show changes
|
|
You can try these changes here
|
The emitter had three separate TypeSpec-scalar-to-C#-type-name maps, and they disagreed. Properties were rendered from one, error-model constructor parameters from another, and constraint attribute type arguments from a third — so the generated code did not compile:
public partial class ValidationError : HttpServiceException { public required DateTimeOffset OccurredAt { get; set; } public required string Docs { get; set; } public required SByte Severity { get; set; } - public ValidationError(DateTimeOffset occurredAt, Uri docs, sbyte severity) + public ValidationError(DateTimeOffset occurredAt, string docs, SByte severity)NumericConstraint<T>had the same problem — the attribute was instantiated with a different type than the property it annotated, so it failed to bind.The three maps collapse into one
scalar-overrides.tsthat layers the emitter's deliberate divergences (plainDate/plainTime→DateTime,url→string,safeint→long, CLR names for sized integers) over the emitter framework defaults. Anywhere a C# type name is needed outside a rendering context now goes through it, so it cannot drift from whatTypeExpressionrenders again.Part of a 7-PR stack moving
@typespec/http-server-csharponto the emitter framework. Stacked on #11599 — only the last commit is new here.