diff --git a/src/xunit.analyzers.tests/Analyzers/X1000/InlineDataMustMatchTheoryParametersTests.cs b/src/xunit.analyzers.tests/Analyzers/X1000/InlineDataMustMatchTheoryParametersTests.cs index fd8cfbc4..57a6157f 100644 --- a/src/xunit.analyzers.tests/Analyzers/X1000/InlineDataMustMatchTheoryParametersTests.cs +++ b/src/xunit.analyzers.tests/Analyzers/X1000/InlineDataMustMatchTheoryParametersTests.cs @@ -313,6 +313,24 @@ public void TestMethod(byte[] input) { } await Verify.VerifyAnalyzer(source); } + + // https://github.com/xunit/xunit/issues/3000 + [Fact] + public async Task DecimalValue() + { + var source = /* lang=c#-test */ """ + using Xunit; + + public sealed class ReproClass { + [Theory] + [InlineData({|CS0182:0.1m|})] + public void ReproMethod(decimal m) + { } + } + """; + + await Verify.VerifyAnalyzer(source); + } } public class X1009_TooFewValues diff --git a/src/xunit.analyzers/X1000/InlineDataMustMatchTheoryParameters.cs b/src/xunit.analyzers/X1000/InlineDataMustMatchTheoryParameters.cs index 562a359b..ba1e656b 100644 --- a/src/xunit.analyzers/X1000/InlineDataMustMatchTheoryParameters.cs +++ b/src/xunit.analyzers/X1000/InlineDataMustMatchTheoryParameters.cs @@ -97,6 +97,11 @@ public override void AnalyzeCompilation( var parameter = method.Parameters[paramIdx]; var value = values[valueIdx]; + // If the value isn't legal (malformed or illegal type), then just skip validation and let + // the compiler report the problem. + if (value.Kind == TypedConstantKind.Error) + continue; + // If the parameter type is object, everything is compatible, though we still need to check for nullability if (SymbolEqualityComparer.Default.Equals(parameter.Type, compilation.ObjectType) && (!value.IsNull || parameter.Type.NullableAnnotation != NullableAnnotation.NotAnnotated))