Handle and emit diagnostic for initializer expressions
このコミットが含まれているのは:
1 親
45455abda9
コミット
1826122849
6ファイル変更
+42
-5
検索条件に一致するファイルはありません
+9
-3
@@ -11,11 +11,17 @@ partial class HlslSourceRewriter
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitAnonymousObjectCreationExpression(AnonymousObjectCreationExpressionSyntax node)
|
||||
{
|
||||
AnonymousObjectCreationExpressionSyntax updatedNode = (AnonymousObjectCreationExpressionSyntax)base.VisitAnonymousObjectCreationExpression(node)!;
|
||||
|
||||
Diagnostics.Add(AnonymousObjectCreationExpression, node);
|
||||
|
||||
return updatedNode;
|
||||
return base.VisitAnonymousObjectCreationExpression(node);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitInitializerExpression(InitializerExpressionSyntax node)
|
||||
{
|
||||
Diagnostics.Add(InitializerExpression, node);
|
||||
|
||||
return base.VisitInitializerExpression(node);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
||||
@@ -124,8 +124,11 @@ internal abstract partial class HlslSourceRewriter : CSharpSyntaxRewriter
|
||||
Diagnostics.Add(InvalidObjectCreationExpression, node, type);
|
||||
}
|
||||
|
||||
// Mutate the syntax like with explicit object creation expressions
|
||||
if (updatedNode.ArgumentList!.Arguments.Count == 0)
|
||||
// Mutate the syntax like with explicit object creation expressions. This also handles object
|
||||
// initializer expressions. If those are used, the HLSL will just contain a default expression.
|
||||
// There is a diagnostic being emitted to inform the users if that path is hit. If users want
|
||||
// to create an object and immediately set some values, they should use a factory method.
|
||||
if (updatedNode is not { ArgumentList.Arguments.Count: > 0, Initializer: null })
|
||||
{
|
||||
return CastExpression(targetType, LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(0)));
|
||||
}
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする