Skip to content
Merged
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
14 changes: 13 additions & 1 deletion TUnit.Analyzers/TestDataAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -410,12 +410,24 @@ private void CheckMethodDataSource(SymbolAnalysisContext context,
IPropertySymbol? propertySymbol = null)
{
{
// Guard against missing constructor arguments (can happen during compilation errors)
if (attribute.ConstructorArguments.IsDefaultOrEmpty)
{
return;
}

var type = attribute.AttributeClass?.IsGenericType == true
? attribute.AttributeClass.TypeArguments.First()
: attribute.ConstructorArguments[0].Value as INamedTypeSymbol ?? testClassType;

var methodName = attribute.ConstructorArguments[0].Value as string
?? attribute.ConstructorArguments[1].Value as string;
?? (attribute.ConstructorArguments.Length > 1 ? attribute.ConstructorArguments[1].Value as string : null);

// If method name couldn't be resolved, skip validation (compilation error will be reported separately)
if (string.IsNullOrEmpty(methodName))
{
return;
}

var argumentsNamedArgument = attribute.NamedArguments
.FirstOrDefault(x => x.Key == "Arguments")
Expand Down
Loading