Tweak properties detection to block all field backed ones

このコミットが含まれているのは:
Sergio Pedri committed 2022-04-29 12:58:19 +02:00
1 親 7d14403632
コミット 1ef6040e58
7ファイル変更
+79 -31

検索条件に一致するファイルはありません

+7 -4
ファイルの表示
@@ -542,15 +542,18 @@ internal static class DiagnosticDescriptors
/// <summary>
/// Gets a <see cref="DiagnosticDescriptor"/> for a property declaration.
/// <para>
/// Format: <c>"The compute shader of type {0} contains an invalid property \"{1}\" declaration (only stateless properties explicitly implementing an interface property can be used)"</c>.
/// </para>
/// </summary>
public static readonly DiagnosticDescriptor PropertyDeclaration = new DiagnosticDescriptor(
public static readonly DiagnosticDescriptor InvalidPropertyDeclaration = new DiagnosticDescriptor(
id: "CMPS0040",
title: "Property declaration",
messageFormat: "Property declarations cannot be used in a compute shader",
title: "Invalid property declaration",
messageFormat: "The compute shader of type {0} contains an invalid property \"{1}\" declaration (only stateless properties explicitly implementing an interface property can be used)",
category: "ComputeSharp.Shaders",
defaultSeverity: DiagnosticSeverity.Error,
isEnabledByDefault: true,
description: "Property declarations cannot be used in a compute shader.",
description: "Property declarations (except for stateless properties explicitly implementing an interface property) cannot be used in a compute shader.",
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
/// <summary>
+13 -9
ファイルの表示
@@ -43,8 +43,8 @@ partial class IShaderGenerator
{
ImmutableArray<Diagnostic>.Builder builder = ImmutableArray.CreateBuilder<Diagnostic>();
// Properties are not supported
DetectAndReportPropertyDeclarations(builder, structDeclarationSymbol);
// Detect invalid properties
DetectAndReportInvalidPropertyDeclarations(builder, structDeclarationSymbol);
// We need to sets to track all discovered custom types and static methods
HashSet<INamedTypeSymbol> discoveredTypes = new(SymbolEqualityComparer.Default);
@@ -493,21 +493,25 @@ partial class IShaderGenerator
}
/// <summary>
/// Finds and reports all declared properties in a shader.
/// Finds and reports all invalid declared properties in a shader.
/// </summary>
/// <param name="diagnostics">The collection of produced <see cref="Diagnostic"/> instances.</param>
/// <param name="structDeclarationSymbol">The input <see cref="INamedTypeSymbol"/> instance to process.</param>
private static void DetectAndReportPropertyDeclarations(ImmutableArray<Diagnostic>.Builder diagnostics, INamedTypeSymbol structDeclarationSymbol)
private static void DetectAndReportInvalidPropertyDeclarations(ImmutableArray<Diagnostic>.Builder diagnostics, INamedTypeSymbol structDeclarationSymbol)
{
foreach (var propertySymbol in structDeclarationSymbol.GetMembers().OfType<IPropertySymbol>())
foreach (var memberSymbol in structDeclarationSymbol.GetMembers())
{
// Ignore explicit interface implementations
if (!propertySymbol.ExplicitInterfaceImplementations.IsDefaultOrEmpty)
// Detect properties that are not explicit interface implementations
if (memberSymbol is IPropertySymbol { ExplicitInterfaceImplementations.IsEmpty: true })
{
return;
diagnostics.Add(InvalidPropertyDeclaration, memberSymbol, structDeclarationSymbol, memberSymbol);
}
diagnostics.Add(DiagnosticDescriptors.PropertyDeclaration, propertySymbol);
// Detect properties causing a field to be generated
if (memberSymbol is IFieldSymbol { AssociatedSymbol: IPropertySymbol associatedProperty })
{
diagnostics.Add(InvalidPropertyDeclaration, associatedProperty, structDeclarationSymbol, associatedProperty);
}
}
}