Skip to content

Regression in 2.3.2: optional enum default value is emitted as int literal, causing CS1503 #132

@YoshihiroIto

Description

@YoshihiroIto

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

  1. Clone the repro:
git clone https://github.com/YoshihiroIto/PureDI-2.3.2-EnumDefault.git
cd PureDI-2.3.2-EnumDefault
  1. Build with 2.3.2:
dotnet build PureDI.EnumDefault.Repro.csproj -c Release -p:PureDiVersion=2.3.2
  1. Observe failure:
error CS1503: Argument 8: cannot convert from 'int' to 'Repro.Domain.FileItemFormats'
  1. Build the exact same source with 2.3.1:
dotnet build PureDI.EnumDefault.Repro.csproj -c Release -p:PureDiVersion=2.3.1
  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

Metadata

Metadata

Labels

bugSomething isn't working

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions