Skip to content

Commit e472648

Browse files
Improved diagnostics of error and warning locations
1 parent 471a2c6 commit e472648

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

src/Pure.DI.Core/Core/Attributes.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,18 @@ public T GetAttribute<TMdAttribute, T>(
3939
}
4040

4141
var args = attr.ConstructorArguments;
42-
if (attributeMetadata.ArgumentPosition >= args.Length)
42+
if (attributeMetadata.ArgumentPosition >= args.Length || args[attributeMetadata.ArgumentPosition].Kind == TypedConstantKind.Error)
4343
{
4444
if (attr.ApplicationSyntaxReference?.GetSyntax() is AttributeSyntax { ArgumentList: {} argumentList }
4545
&& attributeMetadata.ArgumentPosition < argumentList.Arguments.Count)
4646
{
4747
return semantic.GetConstantValue<T>(semanticModel, argumentList.Arguments[attributeMetadata.ArgumentPosition].Expression, GetSmartTagKind(kind))
4848
?? defaultValue;
4949
}
50+
}
5051

52+
if (attributeMetadata.ArgumentPosition >= args.Length)
53+
{
5154
throw new CompileErrorException(
5255
string.Format(Strings.Error_Template_InvalidAttributeArgumentPosition, attributeMetadata.ArgumentPosition, attributeMetadata.Source, args.Length),
5356
locationProvider.GetLocation(attributeMetadata.Source),

src/Pure.DI.Core/Core/Semantic.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,11 @@ when memberAccessExpressionSyntax.IsKind(SyntaxKind.SimpleMemberAccessExpression
116116
return valueStr switch
117117
{
118118
nameof(Tag.Type) when IsSpecialType(semanticModel, node, SpecialType.Tag) => (T)(object)Tag.Type,
119-
nameof(Tag.Unique) when IsSpecialType(semanticModel, node, SpecialType.Tag) => (T)(object)Tag.Unique,
119+
nameof(Tag.Unique) when smartTagKind == SmartTagKind.Tag && IsSpecialType(semanticModel, node, SpecialType.Tag) => (T)(object)Tag.Unique,
120120
_ => (T)smartTags.Register(SmartTagKind.Tag, valueStr)
121121
};
122122

123-
case nameof(Name) when typeof(T) == typeof(object):
123+
case nameof(Name) when smartTagKind == SmartTagKind.Name && typeof(T) == typeof(object):
124124
return (T)smartTags.Register(SmartTagKind.Name, valueStr);
125125
}
126126
}

0 commit comments

Comments
 (0)