Skip to content

Fix source generator numeric default value types and add nint/nuint support#172

Merged
hadashiA merged 1 commit intomasterfrom
fix/source-generator-numeric-default-values
Mar 9, 2026
Merged

Fix source generator numeric default value types and add nint/nuint support#172
hadashiA merged 1 commit intomasterfrom
fix/source-generator-numeric-default-values

Conversation

@hadashiA
Copy link
Copy Markdown
Owner

@hadashiA hadashiA commented Mar 9, 2026

Summary

  • Fix source generator emitting wrong types for numeric constructor default values (fixes Source generator numeric type error #166)
    • EmitDefaultValue() now uses MemberType.SpecialType instead of runtime type pattern matching, because Roslyn may box numeric default values as int regardless of the actual parameter type (e.g. ushort address = 0 was emitted as var __Address__ = 0 instead of var __Address__ = (ushort)0)
    • Added coverage for short, sbyte, char, long, and enum types
  • Add nint/nuint formatter support (NativeIntFormatter, NativeUIntFormatter and their nullable variants)

Test plan

  • Added WithNumericDefaultValues test type with ushort = 0, short = 0, sbyte = 0 default params
  • Added Deserialize_NumericDefaultValues and Deserialize_NumericDefaultValues_PartialOverride tests
  • Added SerializeDeserialize_NativeInt and SerializeDeserialize_NativeUInt tests
  • All 385 existing tests pass

🤖 Generated with Claude Code

…nd add nint/nuint support

Use MemberType.SpecialType instead of runtime type pattern matching in EmitDefaultValue(),
because Roslyn may box numeric default values as int regardless of the parameter type (fixes #166).
Also add nint/nuint formatters and register them in BuiltinResolver.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@hadashiA hadashiA force-pushed the fix/source-generator-numeric-default-values branch from daf800b to f388a2f Compare March 9, 2026 09:56
@hadashiA hadashiA merged commit 489b928 into master Mar 9, 2026
1 check passed
@hadashiA hadashiA deleted the fix/source-generator-numeric-default-values branch March 9, 2026 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Source generator numeric type error

1 participant