diff --git a/src/ComputeSharp.SourceGenerators/AnalyzerReleases.Unshipped.md b/src/ComputeSharp.SourceGenerators/AnalyzerReleases.Unshipped.md
index c5fc51d1..6d879574 100644
--- a/src/ComputeSharp.SourceGenerators/AnalyzerReleases.Unshipped.md
+++ b/src/ComputeSharp.SourceGenerators/AnalyzerReleases.Unshipped.md
@@ -39,4 +39,5 @@ CMPS0031 | ComputeSharp.IComputeShader | Error | IComputeShaderSourceGenerator,
CMPS0032 | ComputeSharp.IComputeShader | Error | IComputeShaderSourceGenerator, [Documentation](https://github.com/Sergio0694/ComputeSharp)
CMPS0033 | ComputeSharp.IComputeShader | Error | IComputeShaderSourceGenerator, [Documentation](https://github.com/Sergio0694/ComputeSharp)
CMPS0034 | ComputeSharp.IComputeShader | Error | IComputeShaderSourceGenerator, [Documentation](https://github.com/Sergio0694/ComputeSharp)
-CMPS0035 | ComputeSharp.IComputeShader | Error | IComputeShaderSourceGenerator, [Documentation](https://github.com/Sergio0694/ComputeSharp)
\ No newline at end of file
+CMPS0035 | ComputeSharp.IComputeShader | Error | IComputeShaderSourceGenerator, [Documentation](https://github.com/Sergio0694/ComputeSharp)
+CMPS0036 | ComputeSharp.IComputeShader | Error | IComputeShaderSourceGenerator, [Documentation](https://github.com/Sergio0694/ComputeSharp)
\ No newline at end of file
diff --git a/src/ComputeSharp.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs b/src/ComputeSharp.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs
index 119f197f..50676fd5 100644
--- a/src/ComputeSharp.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs
+++ b/src/ComputeSharp.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs
@@ -494,5 +494,18 @@ namespace ComputeSharp.SourceGenerators.Diagnostics
isEnabledByDefault: true,
description: "The unsafe modifier cannot be used in methods or functions used in a compute shader.",
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
+
+ ///
+ /// Gets a for a string literal.
+ ///
+ public static DiagnosticDescriptor StringLiteralExpression { get; } = new(
+ id: "CMPS0036",
+ title: "String literal expression",
+ messageFormat: "String literal expressions cannot be used in a compute shader",
+ category: typeof(IComputeShader).FullName,
+ defaultSeverity: DiagnosticSeverity.Error,
+ isEnabledByDefault: true,
+ description: "String literal expressions cannot be used in a compute shader.",
+ helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
}
}
diff --git a/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ShaderSourceRewriter.cs b/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ShaderSourceRewriter.cs
index 75870fd3..38cf34f3 100644
--- a/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ShaderSourceRewriter.cs
+++ b/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ShaderSourceRewriter.cs
@@ -316,6 +316,10 @@ namespace ComputeSharp.SourceGenerators.SyntaxRewriters
return updatedNode.WithToken(Literal(updatedNode.Token.ValueText + "L", 0d));
}
}
+ else if (updatedNode.IsKind(SyntaxKind.StringLiteralExpression))
+ {
+ this.context.ReportDiagnostic(StringLiteralExpression, node);
+ }
return updatedNode;
}
diff --git a/tests/ComputeSharp.Tests.Internals.SourceGenerators/DiagnosticsTests.cs b/tests/ComputeSharp.Tests.Internals.SourceGenerators/DiagnosticsTests.cs
index 1abacd1b..81336d41 100644
--- a/tests/ComputeSharp.Tests.Internals.SourceGenerators/DiagnosticsTests.cs
+++ b/tests/ComputeSharp.Tests.Internals.SourceGenerators/DiagnosticsTests.cs
@@ -1070,6 +1070,33 @@ namespace ComputeSharp.Tests.Internals
VerifyGeneratedDiagnostics(source, "CMPS0035");
}
+ [TestMethod]
+ public void StringLiteralExpression()
+ {
+ string source = @"
+ using ComputeSharp;
+
+ namespace ComputeSharp
+ {
+ public class ReadWriteBuffer { }
+ }
+
+ namespace MyFancyApp.Sample
+ {
+ public struct MyShader : IComputeShader
+ {
+ public ReadWriteBuffer buffer;
+
+ public void Execute()
+ {
+ _ = ""Hello world"";
+ }
+ }
+ }";
+
+ VerifyGeneratedDiagnostics(source, "CMPS0036");
+ }
+
///
/// Verifies the output of a source generator.
///