Summary
After upgrading Pure.DI from 2.3.1 to 2.3.2, code generation fails to compile when a constructor has an optional
enum parameter with a non-zero default value.
Compiler error:
CS1503: Argument 8: cannot convert from 'int' to 'Repro.Domain.FileItemFormats'
Repro repository
https://github.com/YoshihiroIto/PureDI-2.3.2-EnumDefault
Regression range
- 2.3.1: works
- 2.3.2: fails
Steps to reproduce
- Clone the repro:
git clone https://github.com/YoshihiroIto/PureDI-2.3.2-EnumDefault.git
cd PureDI-2.3.2-EnumDefault
- Build with 2.3.2:
dotnet build PureDI.EnumDefault.Repro.csproj -c Release -p:PureDiVersion=2.3.2
- Observe failure:
error CS1503: Argument 8: cannot convert from 'int' to 'Repro.Domain.FileItemFormats'
- Build the exact same source with 2.3.1:
dotnet build PureDI.EnumDefault.Repro.csproj -c Release -p:PureDiVersion=2.3.1
- Observe build succeeds.
Actual behavior
In 2.3.2, generated Composition.g.cs includes a raw int literal for the optional enum parameter:
return new global::Service(new global::Dependency1(), new global::Dependency2(), new global::Dependency3(), new
global::Dependency4(), new global::Dependency5(), new global::Dependency6(), new global::Dependency7(), 7);
This fails because the parameter type is Repro.Domain.FileItemFormats.
Expected behavior
Generated code should remain type-safe for optional enum parameters, e.g. by:
- omitting the optional parameter, or
- emitting a typed enum value/cast instead of raw int.
Environment
- OS: Windows
- .NET SDK: 10.0.103
- Target framework: net10.0
Summary
After upgrading Pure.DI from
2.3.1to2.3.2, code generation fails to compile when a constructor has an optionalenum parameter with a non-zero default value.
Compiler error:
Repro repository
https://github.com/YoshihiroIto/PureDI-2.3.2-EnumDefault
Regression range
Steps to reproduce
Actual behavior
In 2.3.2, generated Composition.g.cs includes a raw int literal for the optional enum parameter:
This fails because the parameter type is Repro.Domain.FileItemFormats.
Expected behavior
Generated code should remain type-safe for optional enum parameters, e.g. by:
Environment