Skip to content

Conversation

@MichaelSimons
Copy link
Member

This PR supersedes #357.

The following hand edits were necessary:

  1. Declare Microsoft.CodeAnalysis.CSharp a friend of Microsoft.CodeAnalysis.Common
  2. Added hand crafted internal stubs in Microsoft.CodeAnalysis.Common and Microsoft.CodeAnalysis.Workspaces.Common
  3. NoWarned RS1025 and RS1026
  4. Worked around Add SBRP support for meta packages source-build#2949 by replacing System.Composition references with the set of System.Composition.* references
  5. Removed the Microsoft.CodeAnalysis.Analyzers reference. Tooling does not support analyzers packages. Analyzers are not run as part of source-build so I don't think this will be a problem. Will validate in an E2E tarball build.
  6. Removed netcoreapp3.1 artifacts from the Microsoft.CodeAnalysis.* packages
  7. The generated code causes a number of errors similar to the following:
  /repos/source-build-reference-packages/artifacts/source-build/self/src/src/referencePackages/src/microsoft.codeanalysis.csharp/4.0.1/lib/netstandard2.0/Microsoft.CodeAnalysis.CSharp.cs(2820,34): error CS0453: The type 'TResult' must be a non-nullable value type in order to use it as parameter 'T' in the generic type or method 'Nullable<T>' [/repos/source-build-reference-packages/artifacts/source-build/self/src/src/referencePackages/src/microsoft.codeanalysis.csharp/4.0.1/Microsoft.CodeAnalysis.CSharp.4.0.1.csproj] [/root/.nuget/packages/microsoft.dotnet.arcade.sdk/7.0.0-beta.22376.3/tools/Build.proj]
  /repos/source-build-reference-packages/artifacts/source-build/self/src/src/referencePackages/src/microsoft.codeanalysis.csharp/4.0.1/lib/netstandard2.0/Microsoft.CodeAnalysis.CSharp.cs(2841,34): error CS0508: 'AccessorListSyntax.Accept<TResult>(CSharpSyntaxVisitor<TResult>)': return type must be 'TResult' to match overridden member 'CSharpSyntaxNode.Accept<TResult>(CSharpSyntaxVisitor<TResult>)' [/repos/source-build-reference-packages/artifacts/source-build/self/src/src/referencePackages/src/microsoft.codeanalysis.csharp/4.0.1/Microsoft.CodeAnalysis.CSharp.4.0.1.csproj] [/root/.nuget/packages/microsoft.dotnet.arcade.sdk/7.0.0-beta.22376.3/tools/Build.proj]

This is caused by the following override:

public override TResult? Accept<TResult>(CSharpSyntaxVisitor<TResult> visitor)

The generated code was missing the following generic constraint which I hand added: where TResult : default

This situation is documented here:

The addition of nullable reference types introduces a potential ambiguity in the meaning of T? in generic methods. If T is a struct, T? is the same as [System.Nullable<T>](https://docs.microsoft.com/en-us/dotnet/api/system.nullable-1). However, if T is a reference type, T? means that null is a valid value. The ambiguity arises because overriding methods can't include constraints. The new default constraint resolves this ambiguity.

cc @andriipatsula, @chsienki

@MichaelSimons MichaelSimons merged commit 66bca43 into dotnet:main Jul 29, 2022
@MichaelSimons MichaelSimons deleted the ca-test branch July 29, 2022 13:14
MichaelSimons added a commit to MichaelSimons/source-build-reference-packages that referenced this pull request Jun 16, 2025
MichaelSimons added a commit to MichaelSimons/source-build-reference-packages that referenced this pull request Jun 17, 2025
MichaelSimons added a commit to MichaelSimons/source-build-reference-packages that referenced this pull request Jun 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants