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
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,17 @@ public static InvocationExpressionSyntax WithArguments(InvocationExpressionSynta
private sealed class BindingContext(SemanticModel semanticModel, InvocationExpressionSyntax invocationExpression, string? namespaceToImport, CancellationToken cancellationToken)
{
private readonly bool _isInConditionalAccess = IsInConditionalAccess(invocationExpression.Expression);

// An attribute argument must be a constant (CS0182), so an invocation cannot be one, and the speculative binding can throw there
private readonly bool _isInAttributeArgument = invocationExpression.FirstAncestorOrSelf<AttributeArgumentSyntax>() is not null;

private (SemanticModel SemanticModel, int Position)? _bindingLocation;

public IMethodSymbol? GetTargetMethod(InvocationExpressionSyntax newInvocation)
{
if (_isInAttributeArgument)
return null;

if (_isInConditionalAccess)
{
var (newSemanticModel, newNode) = ReplaceInvocation(newInvocation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1283,4 +1283,21 @@ public static class SampleExtensions

return test.RunAsync();
}

[Fact]
[Trait("Issue", "https://github.com/meziantou/Meziantou.Analyzer/issues/1686")]
public Task InvalidCode_InvocationInAttributeArgument_NoCodeFix()
{
const string Source = """
[assembly:({|MA0011:string.Format(""new object[]{-1a is g System
|}using>
""";
var test = CreateTest();
// The code does not compile, so the compiler diagnostics cannot be verified
test.CompilerDiagnostics = CompilerDiagnostics.None;
test.TestCode = Source;
test.FixedCode = Source;

return test.RunAsync();
}
}
Loading