NativeAOT substitutions only support Boolean and Int32 constants
- Dominant language
- C#
- Stars
- 18.3k
- Forks
- 5.6k
- PR merge metrics
- PR metrics pending
Description
NativeAOT's `BodySubstitutionParser.TryCreateSubstitution` only handles `TypeFlags.Boolean` and `TypeFlags.Int32`, and `BodySubstitution.EmitIL` assumes every non-empty substituted value is an `int`. ILLink's equivalent substitution implementation supports the wider set of XML constant types, including all enum underlying integer types.
This means NativeAOT cannot process substitutions for fields or stubbed method returns using values such as `byte`, `short`, `uint`, `long`, `ulong`, floating-point values, characters, or strings.
## Repro
```csharp
enum Mode : byte
{
Disabled,
Enabled,
}
static class Settings
{
internal static readonly Mode Current = Mode.Disabled;
}
```
```xml
```
Process the substitution with NativeAOT, for example through an `ILLink.Substitutions.xml` embedded resource.
## Expected behavior
NativeAOT accepts the same substitution constant types as ILLink, including every valid enum underlying integer type.
## Actual behavior
`BodySubstitutionParser.TryCreateSubstitution` reaches its unsupported-type path for the `byte`-backed enum. Supporting wider values also requires updating `BodySubstitution` and substitution consumers, which currently store and propagate only `int` constants.
> [!NOTE]
> *This content was created with assistance from AI.*
Contributor guide
Research direction
Start with BodySubstitutionParser.TryCreateSubstitution and BodySubstitution.EmitIL, then trace the substitution consumers that currently store and propagate int constants. Compare the supported XML constant types with ILLink's implementation and use the byte-backed enum repro through an ILLink.Substitutions.xml embedded resource. Done means NativeAOT accepts the wider constant set, including enum underlying integer types, without regressing existing substitutions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 65/100