diff --git a/src/Zomp.SyncMethodGenerator/AsyncToSyncRewriter.cs b/src/Zomp.SyncMethodGenerator/AsyncToSyncRewriter.cs index 5665fd8..6b12bc3 100644 --- a/src/Zomp.SyncMethodGenerator/AsyncToSyncRewriter.cs +++ b/src/Zomp.SyncMethodGenerator/AsyncToSyncRewriter.cs @@ -47,6 +47,14 @@ internal sealed class AsyncToSyncRewriter(SemanticModel semanticModel) : CSharpS SymbolDisplayMiscellaneousOptions.EscapeKeywordIdentifiers | SymbolDisplayMiscellaneousOptions.UseSpecialTypes); + private static readonly SymbolDisplayFormat GlobalDisplayFormatWithTypeParameters = new( + globalNamespaceStyle: SymbolDisplayGlobalNamespaceStyle.Included, + typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces, + genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters, + miscellaneousOptions: + SymbolDisplayMiscellaneousOptions.EscapeKeywordIdentifiers | + SymbolDisplayMiscellaneousOptions.UseSpecialTypes); + private static readonly SymbolDisplayFormat NamespaceDisplayFormat = new( typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces, genericsOptions: SymbolDisplayGenericsOptions.None, @@ -254,7 +262,7 @@ static BinaryExpressionSyntax CheckNull(ExpressionSyntax expr) => BinaryExpressi else if (node.Parent is not MemberAccessExpressionSyntax && GetSymbol(node) is IFieldSymbol { IsStatic: true } fieldSymbol) { - var typeString = fieldSymbol.ContainingType.ToDisplayString(GlobalDisplayFormat); + var typeString = fieldSymbol.ContainingType.ToDisplayString(GlobalDisplayFormatWithTypeParameters); return @base.WithIdentifier(Identifier($"{typeString}.{fieldSymbol.Name}")); } diff --git a/tests/GenerationSandbox.Tests/GenerationSandbox.Tests.csproj b/tests/GenerationSandbox.Tests/GenerationSandbox.Tests.csproj index 8e40809..c0c3b3d 100644 --- a/tests/GenerationSandbox.Tests/GenerationSandbox.Tests.csproj +++ b/tests/GenerationSandbox.Tests/GenerationSandbox.Tests.csproj @@ -1,7 +1,7 @@  - $(NoWarn);CS0219;CA1812;CA1852;SA1402;CA1822;SA1201;CA1303;SA1124;IDE0035;CS0162;RS1035;CS8619;CS8603;CA5394 + $(NoWarn);CS0219;CA1812;CA1852;SA1402;CA1822;SA1201;CA1303;SA1124;IDE0035;CS0162;RS1035;CS8619;CS8603;CS1998;CA5394 false net7.0;net6.0 $(TargetFrameworks);net472 diff --git a/tests/Generator.Tests/Snapshots/UnitTests.GenericClassMemberAccess#Test.GenericClass.MethodAsync.g.verified.cs b/tests/Generator.Tests/Snapshots/UnitTests.GenericClassMemberAccess#Test.GenericClass.MethodAsync.g.verified.cs new file mode 100644 index 0000000..0a07c76 --- /dev/null +++ b/tests/Generator.Tests/Snapshots/UnitTests.GenericClassMemberAccess#Test.GenericClass.MethodAsync.g.verified.cs @@ -0,0 +1,11 @@ +//HintName: Test.GenericClass.MethodAsync.g.cs +// +#nullable enable +namespace Test; +partial class GenericClass +{ + public void Method() + { + _ = global::Test.GenericClass.Bar; + } +} diff --git a/tests/Generator.Tests/UnitTests.cs b/tests/Generator.Tests/UnitTests.cs index 30f2317..ab5ba3c 100644 --- a/tests/Generator.Tests/UnitTests.cs +++ b/tests/Generator.Tests/UnitTests.cs @@ -58,6 +58,22 @@ async void EmptyAsync() { } } +""".Verify(sourceType: SourceType.Full); + + [Fact] + public Task GenericClassMemberAccess() => """ +namespace Test; +partial class GenericClass +{ + private const string Bar = "Bar"; + + [CreateSyncVersion] + public async Task MethodAsync() + { + _ = Bar; + } +} + """.Verify(sourceType: SourceType.Full); [Fact]