Sergio0694 / PolySharp

PolySharp provides generated, source-only polyfills for C# language features, to easily use all runtime-agnostic features downlevel. Add a reference, set your C# version to latest and have fun! 🚀
MIT License
1.77k stars 46 forks source link

`IsExternalInit` not generated correctly in multitargeting projects #98

Open Lordfirespeed opened 7 months ago

Lordfirespeed commented 7 months ago

Reproduction Steps

Make a project that targets netstandard2.1 and net8.0

<TargetFrameworks>netstandard2.1;net8.0</TargetFrameworks>

and add a record class to it with some members, or alternatively a class with required init properties.

Expected Behavior

IsExternalInits type should be included in the compiled assembly targeting netstandard2.1.

Actual Behavior

Compilation succeeds, but IsExternalInits type is not included in the compiled assembly targeting netstandard2.1.

System info

This section should contain useful info such as:

AArnott commented 3 months ago

IsExternalInit must be emitted all the time, for all frameworks. Even if the framework already declares it. The explanation of why is here: https://github.com/manuelroemer/IsExternalInit/issues/5

Sergio0694 commented 3 months ago

"IsExternalInit must be emitted all the time, for all frameworks."

This is not accurate. PolySharp generates the correct [TypeForwardedTo] in that case, instead of the polyfill. Not generating the polyfill is only a binary breaking changes if you don't generate the correct forwards, but PolySharp does that, so that's fine.

"Compilation succeeds, but IsExternalInits type is not included in the compiled assembly targeting netstandard2.1."

@Lordfirespeed I need more info from your end. First, I can't repro this:

image

Second, how is your project even compiling at all, if you're saying the .NET Standard 2.1 target doesn't have that polyfill?

Are you sure you're not looking at the wrong place or perhaps it was just VS not showing all generated files correctly?

AArnott commented 3 months ago

@Sergio0694 You are quite right. Brilliant solution that I hadn't thought of so didn't check for. My apologies for spreading FUD.

Sergio0694 commented 3 months ago

All good, no worries! Just wanted to make sure there were no misunderstandings! 😊