question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

False positive "nested constraint" exception when using an argument constraint of the wrong type

See original GitHub issue

Original title: Weird issue with nested constraints and simple types

public interface IEmailFactory
    {
        Task<IList<MailMessage>> GetEmailMessages(long idPairGame, EmailTemplateType emailTemplateType);
    }

_emailFactory = new Fake<IEmailFactory>().FakedObject;

A.CallTo(() => _emailFactory.GetEmailMessages(A<int>._, A<EmailTemplateType>._)).Returns(mailMessages);

EmailTemplateType is an enum. When I change it to int it is still wrong, so it is not an issue.

FakeIt version 4.1.

It throws the following exception

FakeItEasy.Expressions.ExpressionArgumentConstraintFactory.ArgumentConstraintExpressionVisitor.VisitMember(MemberExpression node) at System.Linq.Expressions.MemberExpression.Accept(ExpressionVisitor visitor) at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node) at System.Linq.Expressions.ExpressionVisitor.VisitUnary(UnaryExpression node) at System.Linq.Expressions.UnaryExpression.Accept(ExpressionVisitor visitor) at FakeItEasy.Expressions.ExpressionArgumentConstraintFactory.CheckArgumentExpressionIsValid(Expression expression) at FakeItEasy.Expressions.ExpressionArgumentConstraintFactory.GetArgumentConstraintFromExpression(Expression expression, Object& value) at FakeItEasy.Expressions.ExpressionArgumentConstraintFactory.GetArgumentConstraint(ParsedArgumentExpression argument) at System.Linq.Utilities.<>c__DisplayClass2_03.<CombineSelectors>b__0(TSource x) at System.Linq.Enumerable.SelectEnumerableIterator2.ToArray() at System.Linq.Enumerable.ToArray[TSource](IEnumerable1 source) at FakeItEasy.Expressions.ExpressionCallMatcher..ctor(ParsedCallExpression parsedExpression, ExpressionArgumentConstraintFactory constraintFactory, MethodInfoManager methodInfoManager, Factory outputWriterFactory) at FakeItEasy.RootModule.<>c__DisplayClass0_0.<RegisterDependencies>b__4(ParsedCallExpression callSpecification) at FakeItEasy.Configuration.FakeConfigurationManager.CallTo[T](Expression1 callSpecification)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:15 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
thomaslevesquecommented, Oct 18, 2017

This change has been released as part of FakeItEasy 4.1.1.

Thanks for the report @progala2! Look for your name in the release notes. 🏆

1reaction
thomaslevesquecommented, Oct 13, 2017

There’s a problem in your code: it should be A<long>._, not A<int>._. Since the parameter is of type long, the A<int>._ constraint will never match; in fact, we even added a diagnostic in the latest analyzer.

I think this is what causing the error, since I can’t reproduce the problem when I change the constraint type. However, the exception is clearly incorrect, we definitely have a bug.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Hibernate Validator 8.0.1.Final - Jakarta Bean ...
When applying constraints on an Iterable type argument, Hibernate Validator will validate each element. Example 2.3, “Container element ...
Read more >
Argument constraints
Argument constraints. When configuring and asserting calls in FakeItEasy, the arguments of the call can be constrained so that only calls to the...
Read more >
Method Constraints with Bean Validation 2.0
Here, we'll focus on the different types of method constraints such as: single-parameter constraints; cross-parameter; return constraints. Also, ...
Read more >
Constraints and concepts (since C++20)
In a type-constraint, a concept takes one less template argument than its parameter list demands, because the contextually deduced type is ...
Read more >
Error conditions in Azure Databricks
during a struct expansion; try removing qualifiers if they are used with nested columns. EXPRESSION_TYPE_IS_NOT_ORDERABLE. SQLSTATE: none ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found