From 2291851cdb264f8009e07a4e73ab53a707aedcd1 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 29 Nov 2020 17:30:53 +0100 Subject: [PATCH] Fixed a crash when parsing literal tokens --- .../SyntaxRewriters/ShaderSourceRewriter.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ShaderSourceRewriter.cs b/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ShaderSourceRewriter.cs index dcc5cd45..62577adc 100644 --- a/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ShaderSourceRewriter.cs +++ b/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ShaderSourceRewriter.cs @@ -133,17 +133,17 @@ namespace ComputeSharp.SourceGenerators.SyntaxRewriters /// public override SyntaxNode? VisitLiteralExpression(LiteralExpressionSyntax node) { - node = ((LiteralExpressionSyntax)base.VisitLiteralExpression(node)!); + var updatedNode = ((LiteralExpressionSyntax)base.VisitLiteralExpression(node)!); - if (node.IsKind(SyntaxKind.DefaultLiteralExpression)) + if (updatedNode.IsKind(SyntaxKind.DefaultLiteralExpression)) { - TypeSyntax type = node.ReplaceAndTrackType(this.semanticModel, this.discoveredTypes); + TypeSyntax type = updatedNode.ReplaceAndTrackType(node, this.semanticModel, this.discoveredTypes); // Same HLSL-style expression in the form (T)0 return CastExpression(type, LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(0))); } - return node; + return updatedNode; } /// @@ -249,7 +249,7 @@ namespace ComputeSharp.SourceGenerators.SyntaxRewriters return ParseToken(mapped!); } - return updatedToken; + return updatedToken.WithoutTrivia(); } } }