Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/Orleans.CodeGenerator/GeneratedSourceOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ namespace Orleans.CodeGenerator;

internal static class GeneratedSourceOutput
{
private const string GeneratedCodeWarningDisable = "#pragma warning disable CS1591, RS0016, RS0041";
private const string GeneratedCodeWarningRestore = "#pragma warning restore CS1591, RS0016, RS0041";
private const string GeneratedCodeWarningDisable = "#pragma warning disable";
private const string GeneratedCodeWarningRestore = "#pragma warning restore";

internal static void EmitSourceOutputResult(SourceProductionContext context, SourceOutputResult result)
{
Expand Down Expand Up @@ -380,4 +380,3 @@ internal static string SanitizeHintComponent(string value)
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ namespace Orleans.CodeGenerator.Tests;

public sealed class GeneratedWarningSuppressionTests
{
private const string ObsoleteWithoutMessageDiagnosticId = "CS0612";
private const string ObsoleteWithMessageDiagnosticId = "CS0618";
private const string MissingXmlCommentDiagnosticId = "CS1591";
private const string PublicApiAnalyzerDiagnosticId = "RS0016";
private const string CompilerApiAnalyzerDiagnosticId = "RS0041";
Expand Down Expand Up @@ -46,7 +48,7 @@ public interface IWarningGrain : IGrainWithIntegerKey
}
""";

var compilation = await CreateCompilationWithDocumentationDiagnostics(source);
var compilation = await CreateCompilationWithStrictDiagnostics(source);
var result = RunGenerator(compilation);

Assert.Empty(result.Diagnostics.Where(static diagnostic => diagnostic.Severity == DiagnosticSeverity.Error));
Expand All @@ -72,7 +74,65 @@ public interface IWarningGrain : IGrainWithIntegerKey
}

[Fact]
public async Task GeneratedSources_CompileCleanlyUnderStrictDiagnosticsForMixedSourceAndReferences()
public async Task GeneratedProxySourcesSuppressObsoleteMemberWarnings()
{
const string source = """
using Orleans;
using System;
using System.Threading.Tasks;

namespace TestProject;

public interface IWarningGrain : IGrainWithIntegerKey
{
[Obsolete]
Task OldMethodWithoutMessage();

[Obsolete("Use NewMethod instead.")]
Task OldMethodWithMessage();

Task NewMethod();
}

public static class WarningCaller
{
public static async Task CallObsoleteMethods(IWarningGrain grain)
{
await grain.OldMethodWithoutMessage();
await grain.OldMethodWithMessage();
}
}
""";

var compilation = await CreateCompilationWithStrictDiagnostics(source);
var result = RunGenerator(compilation);

Assert.Empty(result.Diagnostics.Where(static diagnostic => diagnostic.Severity == DiagnosticSeverity.Error));
Assert.Contains(result.GeneratedSources, static source => source.HintName.Contains(".orleans.proxy.", StringComparison.Ordinal));

var generatedCompilation = compilation.AddSyntaxTrees(CreateGeneratedSyntaxTrees(result));
var generatedTreePaths = result.GeneratedSources
.Select(static source => source.HintName)
.ToHashSet(StringComparer.Ordinal);
var obsoleteErrors = generatedCompilation.GetDiagnostics()
.Where(static diagnostic => (diagnostic.Id is ObsoleteWithoutMessageDiagnosticId or ObsoleteWithMessageDiagnosticId)
&& diagnostic.Severity == DiagnosticSeverity.Error)
.ToArray();

Assert.Equal(
new[] { ObsoleteWithoutMessageDiagnosticId, ObsoleteWithMessageDiagnosticId },
obsoleteErrors
.Where(diagnostic => diagnostic.Location.SourceTree is { } tree && !generatedTreePaths.Contains(tree.FilePath))
.Select(static diagnostic => diagnostic.Id)
.OrderBy(static id => id, StringComparer.Ordinal)
.ToArray());
Assert.DoesNotContain(
obsoleteErrors,
diagnostic => diagnostic.Location.SourceTree is { } tree && generatedTreePaths.Contains(tree.FilePath));
}

[Fact]
public async Task GeneratedSourcesCompileCleanlyWhenWarningsAreErrorsForMixedSourceAndReferences()
{
const string librarySource = """
using Orleans;
Expand Down Expand Up @@ -132,7 +192,7 @@ public interface ILocalWarningGrain : IGrainWithIntegerKey
var libraryCompilation = await TestCompilationHelper.CreateCompilation(librarySource, "LibraryProject");
Assert.Empty(libraryCompilation.GetDiagnostics().Where(static diagnostic => diagnostic.Severity == DiagnosticSeverity.Error));

var compilation = await CreateCompilationWithDocumentationDiagnostics(
var compilation = await CreateCompilationWithStrictDiagnostics(
consumerSource,
libraryCompilation.ToMetadataReference());
var result = RunGenerator(compilation);
Expand All @@ -158,7 +218,7 @@ public interface ILocalWarningGrain : IGrainWithIntegerKey
string.Join(Environment.NewLine, generatedErrors));
}

private static async Task<CSharpCompilation> CreateCompilationWithDocumentationDiagnostics(
private static async Task<CSharpCompilation> CreateCompilationWithStrictDiagnostics(
string source,
params MetadataReference[] additionalReferences)
{
Expand All @@ -168,11 +228,15 @@ private static async Task<CSharpCompilation> CreateCompilationWithDocumentationD
DocumentationParseOptions,
path: "WarningSuppressionInput.cs",
encoding: Encoding.UTF8);
var options = compilation.Options.WithSpecificDiagnosticOptions(
compilation.Options.SpecificDiagnosticOptions
.SetItem(MissingXmlCommentDiagnosticId, ReportDiagnostic.Error)
.SetItem(PublicApiAnalyzerDiagnosticId, ReportDiagnostic.Error)
.SetItem(CompilerApiAnalyzerDiagnosticId, ReportDiagnostic.Error));
var options = compilation.Options
.WithGeneralDiagnosticOption(ReportDiagnostic.Error)
.WithSpecificDiagnosticOptions(
compilation.Options.SpecificDiagnosticOptions
.SetItem(ObsoleteWithoutMessageDiagnosticId, ReportDiagnostic.Error)
.SetItem(ObsoleteWithMessageDiagnosticId, ReportDiagnostic.Error)
.SetItem(MissingXmlCommentDiagnosticId, ReportDiagnostic.Error)
.SetItem(PublicApiAnalyzerDiagnosticId, ReportDiagnostic.Error)
.SetItem(CompilerApiAnalyzerDiagnosticId, ReportDiagnostic.Error));

return compilation
.ReplaceSyntaxTree(compilation.SyntaxTrees.Single(), syntaxTree)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1869,7 +1869,7 @@ private static string ConcatenateGeneratedSources(GeneratorRunResult result)
resultText = resultText.Replace(".Add(typeof(int));", ".Add(typeof( int ));", StringComparison.Ordinal);
if (assemblyAttributes.Count > 0)
{
resultText += $"{Environment.NewLine}#pragma warning restore CS1591, RS0016, RS0041";
resultText += $"{Environment.NewLine}#pragma warning restore";
}

return resultText;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma warning disable CS1591, RS0016, RS0041
#pragma warning disable
[assembly: global::Orleans.ApplicationPartAttribute("TestProject")]
[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")]
[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")]
Expand Down Expand Up @@ -75,4 +75,4 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati
}
}
}
#pragma warning restore CS1591, RS0016, RS0041
#pragma warning restore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma warning disable CS1591, RS0016, RS0041
#pragma warning disable
[assembly: global::Orleans.ApplicationPartAttribute("TestProject")]
[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")]
[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")]
Expand Down Expand Up @@ -118,4 +118,4 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati
}
}
}
#pragma warning restore CS1591, RS0016, RS0041
#pragma warning restore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma warning disable CS1591, RS0016, RS0041
#pragma warning disable
[assembly: global::Orleans.ApplicationPartAttribute("TestProject")]
[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")]
[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")]
Expand Down Expand Up @@ -142,4 +142,4 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati
}
}
}
#pragma warning restore CS1591, RS0016, RS0041
#pragma warning restore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma warning disable CS1591, RS0016, RS0041
#pragma warning disable
[assembly: global::Orleans.ApplicationPartAttribute("TestProject")]
[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")]
[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")]
Expand Down Expand Up @@ -218,4 +218,4 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati
}
}
}
#pragma warning restore CS1591, RS0016, RS0041
#pragma warning restore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma warning disable CS1591, RS0016, RS0041
#pragma warning disable
[assembly: global::Orleans.ApplicationPartAttribute("TestProject")]
[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")]
[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")]
Expand Down Expand Up @@ -142,4 +142,4 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati
}
}
}
#pragma warning restore CS1591, RS0016, RS0041
#pragma warning restore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma warning disable CS1591, RS0016, RS0041
#pragma warning disable
[assembly: global::Orleans.ApplicationPartAttribute("TestProject")]
[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")]
[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")]
Expand Down Expand Up @@ -183,4 +183,4 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati
}
}
}
#pragma warning restore CS1591, RS0016, RS0041
#pragma warning restore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma warning disable CS1591, RS0016, RS0041
#pragma warning disable
[assembly: global::Orleans.ApplicationPartAttribute("TestProject")]
[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")]
[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")]
Expand Down Expand Up @@ -120,4 +120,4 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati
}
}
}
#pragma warning restore CS1591, RS0016, RS0041
#pragma warning restore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma warning disable CS1591, RS0016, RS0041
#pragma warning disable
[assembly: global::Orleans.ApplicationPartAttribute("TestProject")]
[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")]
[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")]
Expand Down Expand Up @@ -124,4 +124,4 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati
}
}
}
#pragma warning restore CS1591, RS0016, RS0041
#pragma warning restore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma warning disable CS1591, RS0016, RS0041
#pragma warning disable
[assembly: global::Orleans.ApplicationPartAttribute("TestProject")]
[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")]
[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")]
Expand Down Expand Up @@ -264,4 +264,4 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati
}
}
}
#pragma warning restore CS1591, RS0016, RS0041
#pragma warning restore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma warning disable CS1591, RS0016, RS0041
#pragma warning disable
[assembly: global::Orleans.ApplicationPartAttribute("TestProject")]
[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")]
[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")]
Expand Down Expand Up @@ -74,4 +74,4 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati
}
}
}
#pragma warning restore CS1591, RS0016, RS0041
#pragma warning restore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma warning disable CS1591, RS0016, RS0041
#pragma warning disable
[assembly: global::Orleans.ApplicationPartAttribute("TestProject")]
[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")]
[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")]
Expand Down Expand Up @@ -163,4 +163,4 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati
}
}
}
#pragma warning restore CS1591, RS0016, RS0041
#pragma warning restore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma warning disable CS1591, RS0016, RS0041
#pragma warning disable
[assembly: global::Orleans.ApplicationPartAttribute("TestProject")]
[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")]
[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")]
Expand Down Expand Up @@ -318,4 +318,4 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati
}
}
}
#pragma warning restore CS1591, RS0016, RS0041
#pragma warning restore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma warning disable CS1591, RS0016, RS0041
#pragma warning disable
[assembly: global::Orleans.ApplicationPartAttribute("TestProject")]
[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")]
[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")]
Expand Down Expand Up @@ -318,4 +318,4 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati
}
}
}
#pragma warning restore CS1591, RS0016, RS0041
#pragma warning restore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma warning disable CS1591, RS0016, RS0041
#pragma warning disable
[assembly: global::Orleans.ApplicationPartAttribute("TestProject")]
[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")]
[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")]
Expand Down Expand Up @@ -158,4 +158,4 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati
}
}
}
#pragma warning restore CS1591, RS0016, RS0041
#pragma warning restore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma warning disable CS1591, RS0016, RS0041
#pragma warning disable
[assembly: global::Orleans.ApplicationPartAttribute("TestProject")]
[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")]
[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")]
Expand Down Expand Up @@ -138,4 +138,4 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati
}
}
}
#pragma warning restore CS1591, RS0016, RS0041
#pragma warning restore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma warning disable CS1591, RS0016, RS0041
#pragma warning disable
[assembly: global::Orleans.ApplicationPartAttribute("TestProject")]
[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")]
[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")]
Expand Down Expand Up @@ -146,4 +146,4 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati
}
}
}
#pragma warning restore CS1591, RS0016, RS0041
#pragma warning restore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma warning disable CS1591, RS0016, RS0041
#pragma warning disable
[assembly: global::Orleans.ApplicationPartAttribute("TestProject")]
[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")]
[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")]
Expand Down Expand Up @@ -171,4 +171,4 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati
}
}
}
#pragma warning restore CS1591, RS0016, RS0041
#pragma warning restore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma warning disable CS1591, RS0016, RS0041
#pragma warning disable
[assembly: global::Orleans.ApplicationPartAttribute("TestProject")]
[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")]
[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")]
Expand Down Expand Up @@ -150,4 +150,4 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati
}
}
}
#pragma warning restore CS1591, RS0016, RS0041
#pragma warning restore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma warning disable CS1591, RS0016, RS0041
#pragma warning disable
[assembly: global::Orleans.ApplicationPartAttribute("TestProject")]
[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")]
[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")]
Expand Down Expand Up @@ -132,4 +132,4 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati
}
}
}
#pragma warning restore CS1591, RS0016, RS0041
#pragma warning restore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma warning disable CS1591, RS0016, RS0041
#pragma warning disable
[assembly: global::Orleans.ApplicationPartAttribute("TestProject")]
[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")]
[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")]
Expand Down Expand Up @@ -123,4 +123,4 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati
}
}
}
#pragma warning restore CS1591, RS0016, RS0041
#pragma warning restore
Loading