Skip to content

Commit

Permalink
xunit/xunit#3000: xUnit1012 when using [InlineData(<decimal>)]
Browse files Browse the repository at this point in the history
  • Loading branch information
bradwilson committed Aug 25, 2024
1 parent c83af22 commit 5d9f063
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 5d9f063

Please sign in to comment.