Closed ap0llo closed 7 months ago
I tried to track down the problem by debugging into Cake.
The issue seems to be in ParameterEmitter.
It writes out all of the method parameter's attributes into the generated Cake script, including System.Runtime.CompilerServices.NullableAttribute
.
But the nullable attribute is a little special, since it does not seem to exist in the BCL but instead the C# compiler generates it into the addin assembly as internal
class.
This attribute is thus not visible to the generated Cake script, causing the compilation error.
I could see multiple ways to fix this
Nullable
attribute and simply ignore it when generating the alias methodNullable
attribute and emit the proper nullability annotations in the generated script
I hope this information is helpful. I'd be happy in assisting with a bugfix and provide a PR once I know what the fix should look like
Ideally the proxy methods generated would have the same signature as the original addin extension method with the exception of the context being supplied.
The warnings could once be pragma disabled and enabled before and after method generation.
Ideally the proxy methods generated would have the same signature as the original addin extension method with the exception of the context being supplied.
The warnings could once be pragma disabled and enabled before and after method generation.
Okay, so that would point to special-casing the "Nullable" attribute and emitting a ?
in the proper places.
I'll see what I can come up with.
:tada: This issue has been resolved in version v4.0.0 :tada:
The release is available on:
Your GitReleaseManager bot :package::rocket:
Prerequisites
Cake runner
Cake .NET Tool
Cake version
3.1
Operating system
Windows
Operating system architecture
64-Bit
CI Server
No response
What are you seeing?
I created an alias with an parameter that is allowed to be
null
and is thus marked as nullable, e.g.When the assembly that contains the alias is used in a Cake script, compilation of the script fails with the following error(s)
What is expected?
I would expect the script to be executed successfully, even is nullable reference types do not seem to be enabled in the scripting runner.
Steps to Reproduce
I prepared a repo here: https://github.com/ap0llo/repro-cake-nullable-reference-types-in-alias
build.cake
file that loads "ExampleAddin" using the#reference
preprocessor directiveI added a little more detailed instructions on how to run the repo in the repository's README
Output log