Skip to content

Validate generator diagnostics after incremental updates - #82113

Merged
jjonescz merged 3 commits into
dotnet:mainfrom
jjonescz:82032-diagnostic-check
Feb 25, 2026
Merged

Validate generator diagnostics after incremental updates#82113
jjonescz merged 3 commits into
dotnet:mainfrom
jjonescz:82032-diagnostic-check

Conversation

@jjonescz

Copy link
Copy Markdown
Member

Fixes #82032.

@jjonescz
jjonescz requested a review from JoeRobich January 22, 2026 16:44
@jjonescz
jjonescz marked this pull request as ready for review January 22, 2026 17:54
@jjonescz
jjonescz requested a review from a team as a code owner January 22, 2026 17:54
string parameterName,
bool initialization = false)
{
_output.WriteLine(diagnostic.ToString());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

needed?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It was useful to see the stacktrace that customers will see even though we don't validate it in the test obviously

Co-authored-by: Cyrus Najmabadi <cyrus.najmabadi@gmail.com>
Also should make it work under non-English locales.
@jjonescz

Copy link
Copy Markdown
Member Author

@dotnet/roslyn-compiler for another review, thanks

#endif
_output.WriteLine(diagnostic.ToString());

var expectedMessage = new ArgumentException(message: message, paramName: parameterName).Message;

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.

Neat :)

@jjonescz
jjonescz requested a review from a team January 26, 2026 10:21
@jaredpar

Copy link
Copy Markdown
Member

If this is merged, what would the behavior for the original bug be with the new code? The generator keeps running but there are some yellow bars, generator stops running, etc ...?

@jjonescz

jjonescz commented Jan 28, 2026

Copy link
Copy Markdown
Member Author

It looks like the generator keeps running in either case (and so the crash is being reported repeatedly).
I don't see any indication in the IDE when the generator fails in the controlled manner (i.e., the state after this PR) which is not specific to this PR, we always handled generator crashes in many other scenarios previously, so I assume that's by design or a pre-existing bug.
I see these when the language server crashes (i.e., the state before this PR):

IDE Crash
VSCode image
VS image

@jjonescz
jjonescz requested a review from jaredpar January 28, 2026 09:39
@jjonescz

jjonescz commented Jan 30, 2026

Copy link
Copy Markdown
Member Author

@dotnet/roslyn-compiler for another review, thanks

(not sure if sign off from Cyrus + Chris counts as two compiler reviews)

@jjonescz

jjonescz commented Feb 4, 2026

Copy link
Copy Markdown
Member Author

@RikkiGibson @dotnet/roslyn-compiler for another review, thanks

@jjonescz

Copy link
Copy Markdown
Member Author

@dotnet/roslyn-compiler for another review, thanks

@jjonescz

Copy link
Copy Markdown
Member Author

@RikkiGibson @dotnet/roslyn-compiler for another review, thanks

@jjonescz

Copy link
Copy Markdown
Member Author

@dotnet/roslyn-compiler for another review, thanks

@jjonescz
jjonescz merged commit 65177ac into dotnet:main Feb 25, 2026
24 checks passed
@jjonescz
jjonescz deleted the 82032-diagnostic-check branch February 25, 2026 16:59
@dotnet-policy-service dotnet-policy-service Bot added this to the Next milestone Feb 25, 2026
@jjonescz jjonescz modified the milestones: Next, 18.6 Mar 31, 2026
ANcpLua added a commit to ANcpLua/ANcpLua.Roslyn.Utilities that referenced this pull request Jun 14, 2026
* test: pin diagnostic-location safety across incremental updates

Mirrors the bug class fixed by dotnet/roslyn#82113 (issue #82032), from the
consumer side. A generator diagnostic whose location was captured against a
longer tree must not survive a shrinking incremental edit as an out-of-range
span. Our DiagnosticInfo/LocationInfo reconstruct an external-file location
(never source-tree-bound), so the driver never range-validates it and a shrink
can neither crash the generator nor report a stale span.

The test drives CSharpGeneratorDriver across a shrinking ReplaceSyntaxTree edit
and asserts the re-reported AL0301 location is external (IsInSource == false)
and in range of the new tree, with no generator-failure diagnostic. It fails if
LocationInfo.ToLocation() ever regresses to a source-tree-bound location.

Bonus: extract a public GeneratorTestHelper.CreateCompilation primitive (reused
by RunGenerator) so tests can drive the driver directly for incremental
scenarios, and declare the now-direct Microsoft.CodeAnalysis.CSharp dependency
on the DU test project.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* ci: execute tests in CI so publish is gated on behavior, not just compile

The build job compiled the test projects but never ran them, so a runtime
regression could pass CI and auto-publish to nuget.org. Add a Test step after
Build on both ubuntu + windows. publish `needs: build`, so a failing test now
fails the job and blocks the release — closing the gap without touching the
fleet-managed branch protection. CrefRegression.Tests stays a compile-only
guard covered by Build (it has no test-platform reference).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Validate generator reported diagnostics

6 participants