Skip to content

Conversation

@chsienki
Copy link
Member

Fixes #54185

In V1 we threw an exception at the point where a duplicate hint name was added. In V2 we were not throwing until we combined all the outputs, meaning a generator had no way of catching and responding to it.

This change restores the immediate exception behavior within the same output node. This means V1 generators will function as before, as the emulation layer executes them within a single node.

V2 generators will have a slightly different behaviour, as we don't know about duplicates until we combine all the outputs (and some may be cached etc). But the author won't see any difference until they have multiple output nodes, so even most ports to V2 should continue to work as written.

@chsienki chsienki added this to the 17.0 milestone Aug 25, 2021
@chsienki chsienki requested a review from a team as a code owner August 25, 2021 23:54
@chsienki
Copy link
Member Author

@dotnet/roslyn-compiler for review please :)

Assert.Equal(2, outputCompilation.SyntaxTrees.Count());
}

[ConditionalFact(typeof(MonoOrCoreClrOnly), Reason = "Desktop CLR displays argument exceptions differently")]
Copy link
Member

Choose a reason for hiding this comment

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

Curious: what is the diff here?

Did you consider using an #if to assert diff between the platforms.

Minor feedback though, don't think it's critical here.

Copy link
Member Author

Choose a reason for hiding this comment

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

CoreCLR has the (param name = '') stuff at the end. We already have a test that does the same thing above, so I just copied it.

@jaredpar
Copy link
Member

@RikkiGibson PTAL

driver.RunGeneratorsAndUpdateCompilation(compilation, out var outputCompilation, out var generatorDiagnostics);
outputCompilation.VerifyDiagnostics();
generatorDiagnostics.Verify(
Diagnostic("CS8785").WithArguments("PipelineCallbackGenerator", "ArgumentException", "The hintName 'test.cs' of the added source file must be unique within a generator. (Parameter 'hintName')").WithLocation(1, 1)
Copy link
Member

Choose a reason for hiding this comment

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

Do we have any test which verifies the case-insensitive comparison for hintNames?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, thats a good one to add, thanks.

Copy link
Member Author

Choose a reason for hiding this comment

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

@chsienki
Copy link
Member Author

Rebase + force to fix conflicts

@chsienki chsienki force-pushed the source-generators/hint-name-collisions branch from 2e1275c to c042eb5 Compare August 31, 2021 22:14
@chsienki chsienki enabled auto-merge (squash) August 31, 2021 22:15
@chsienki chsienki merged commit 4d11231 into dotnet:main Sep 1, 2021
@ghost ghost modified the milestones: 17.0, Next Sep 1, 2021
chsienki added a commit to chsienki/roslyn that referenced this pull request Sep 1, 2021
* Track duplicate hintNames as they are added
jaredpar pushed a commit that referenced this pull request Sep 1, 2021
* Track duplicate hintNames as they are added
@Cosifne Cosifne modified the milestones: Next, 17.0.P5 Sep 27, 2021
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.

Exceptions in additional sources are reported at a different time

4 participants