Skip to content

GH4977: Fix CS8632 for aliases from nullable enabled addins - #4986

Merged
devlead merged 2 commits into
cake-build:developfrom
devlead:feature/gh-4977
Sep 12, 2026
Merged

devlead merged 2 commits into
cake-build:developfrom
devlead:feature/gh-4977

Conversation

@devlead

@devlead devlead commented Sep 12, 2026

Copy link
Copy Markdown
Member

Cake.Tool emits CS8632 for addins compiled with nullable reference types enabled, and
#nullable disable in the .cake file doesn't help, because aliases are generated above the user
script in a compilation where annotations are disabled.

Nullable aware alias generation (#4977)

  • Only aliases that actually carry a nullable annotation are wrapped in #nullable enable /
    #nullable restore. CS8632 is not suppressed anywhere, and scripts keep the oblivious context
    they have today.
  • ? is emitted from NullableAttribute / NullableContextAttribute flag 2, including inner
    generic arguments and array elements, so IList<string?>, string?[]? and Task<string?> all
    round trip.
  • Unconstrained type parameters stay unannotated. NullabilityInfoContext reports every usage of
    such a parameter as nullable, so it can't tell T from T?; for those positions the nullable
    flag of the parameter or return position decides instead.
  • Generic parameter constraints keep their nullability: class? is emitted as class?, and
    notnull is emitted whenever no other constraint implies it, including alongside new().

Dropped CakeSettings on the Cake.dll path (#4985)

CakeRunner.ExecuteScript hand-copies settings onto DotNetExecuteSettings when the resolved tool
path is Cake.dll, which is the default whenever the outer build runs on Cake.Tool.
HandleExitCode, NoWorkingDirectory, PostAction and SetupProcessSettings were missing from
that copy and silently dropped. They're now propagated, which is also what lets the new integration
test capture the nested script's compiler output.

* Propagate HandleExitCode, NoWorkingDirectory, PostAction and SetupProcessSettings to DotNetExecuteSettings
* Add CakeRunnerCoreFixture driving the Cake.dll execution path through the .NET host
* Add CakeRunner tests covering the host path, arguments and the propagated settings
* fixes cake-build#4985
* Wrap only nullable aware generated aliases in #nullable enable/restore, instead of suppressing CS8632 globally
* Emit ? from NullableAttribute flag 2, including inner generic arguments and array elements
* Leave unconstrained type parameters unannotated, as NullabilityInfoContext can't tell T from T? apart
* Emit class?, notnull and notnull combined with new() generic parameter constraints
* Add unit, code generation and integration test coverage for nullable aware aliases
* fixes cake-build#4977
@devlead
devlead requested a review from a team September 12, 2026 20:02

@patriksvensson patriksvensson left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@devlead
devlead merged commit 671642a into cake-build:develop Sep 12, 2026
18 checks passed
This was referenced Sep 14, 2026
This was referenced Sep 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants