Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LibraryImportGenerator, .NET 7: possible error in the 'Equals' method implementation #78145

Closed
VasilievSerg opened this issue Nov 10, 2022 · 11 comments
Labels
area-System.Runtime.InteropServices source-generator Indicates an issue with a source generator feature
Milestone

Comments

@VasilievSerg
Copy link

Description

Code:

public bool Equals(IncrementalStubGenerationContext? other)
{
  return other is not null
               && StubEnvironment.AreCompilationSettingsEqual(Environment, other.Environment)
               && SignatureContext.Equals(other.SignatureContext)
               && ContainingSyntaxContext.Equals(other.ContainingSyntaxContext)
               && StubMethodSyntaxTemplate.Equals(other.StubMethodSyntaxTemplate)
               && LibraryImportData.Equals(other.LibraryImportData)
               && DiagnosticLocation.Equals(DiagnosticLocation)               // <=
               && ForwardedAttributes.SequenceEqual(other.ForwardedAttributes, (IEqualityComparer<AttributeSyntax>)SyntaxEquivalentComparer.Instance)
               && GeneratorFactoryKey.Equals(other.GeneratorFactoryKey)
               && Diagnostics.SequenceEqual(other.Diagnostics);
            }

Link to the sources.

Looks suspicious that DiagnosticLocation compares to itself.

Reproduction Steps

Expected behavior

Actual behavior

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Nov 10, 2022
@ghost
Copy link

ghost commented Nov 10, 2022

Tagging subscribers to this area: @dotnet/interop-contrib
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

Code:

public bool Equals(IncrementalStubGenerationContext? other)
{
  return other is not null
               && StubEnvironment.AreCompilationSettingsEqual(Environment, other.Environment)
               && SignatureContext.Equals(other.SignatureContext)
               && ContainingSyntaxContext.Equals(other.ContainingSyntaxContext)
               && StubMethodSyntaxTemplate.Equals(other.StubMethodSyntaxTemplate)
               && LibraryImportData.Equals(other.LibraryImportData)
               && DiagnosticLocation.Equals(DiagnosticLocation)               // <=
               && ForwardedAttributes.SequenceEqual(other.ForwardedAttributes, (IEqualityComparer<AttributeSyntax>)SyntaxEquivalentComparer.Instance)
               && GeneratorFactoryKey.Equals(other.GeneratorFactoryKey)
               && Diagnostics.SequenceEqual(other.Diagnostics);
            }

Link to the sources.

Looks suspicious that DiagnosticLocation compares to itself.

Reproduction Steps

Expected behavior

Actual behavior

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Author: VasilievSerg
Assignees: -
Labels:

area-System.Runtime.InteropServices, untriaged

Milestone: -

@marek-safar marek-safar added the source-generator Indicates an issue with a source generator feature label Nov 10, 2022
@AaronRobinsonMSFT
Copy link
Member

@VasilievSerg Agreed, this does look odd. Care to submit a PR for adding the other.?

@jkoritzinsky Are we missing a test for this or is this one of those checks that doesn't matter often enough in practice?

@AaronRobinsonMSFT AaronRobinsonMSFT removed the untriaged New issue has not been triaged by the area owner label Nov 10, 2022
@AaronRobinsonMSFT AaronRobinsonMSFT added this to the 8.0.0 milestone Nov 10, 2022
@jkoritzinsky
Copy link
Member

I fixed this in .NET 8 and found that we did have a test validating the behavior. Unfortunately, the test is wrong in .NET 7 and didn't catch it.

The fix and the updated test were part of https://github.com/dotnet/runtime/pull/76474/files#diff-e5ffd09434c9daa4ab5234b83ae383b344c4c20d15a93216b93d358226a10586

In particular, the updates to the AppendingUnrelatedSource_DoesNotRegenerateSource test capture the result of fixing this bug.

@jkoritzinsky
Copy link
Member

Updating the milestone to .NET 7.0.X as this was already fixed in .NET 8.

@jkoritzinsky jkoritzinsky modified the milestones: 8.0.0, 7.0.x Nov 10, 2022
@VasilievSerg
Copy link
Author

I found two more similar places:

  • JSImportGenerator.cs (link);
  • JSExportGenerator.cs (link).

@jkoritzinsky
Copy link
Member

The fix for those was also included in #76474 for .NET 8. It might be worthwhile backporting these fixes to .NET 7 (or all of #76474, which I mentioned in that PR).

@AaronRobinsonMSFT
Copy link
Member

@jkoritzinsky What is the fallout for this? How are customers impacted by this bug?

@jkoritzinsky
Copy link
Member

Diagnostics from the source generator would be reported in the wrong location if the user changes the file above the LibraryImport. This can affect both the IDE experience and an inner-loop command line build experience as the compiler server also has the incremental generator support enabled.

@AaronRobinsonMSFT
Copy link
Member

I see. The referenced PR isn't too big. We can try porting this now or wait until we hear from people. Since it doesn't impact the actual generated code, I don't have a strong opinion either way.

@AaronRobinsonMSFT
Copy link
Member

This doesn't see to be actionable any longer. Closing.

@github-actions github-actions bot locked and limited conversation to collaborators Jun 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Runtime.InteropServices source-generator Indicates an issue with a source generator feature
Projects
None yet
Development

No branches or pull requests

4 participants