Has.Attribute error

Bug #984040 reported by Rechenelf
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
NUnit V2
Fix Released
Medium
Charlie Poole

Bug Description

NUnit 2.5.10 with gui

The following line does not work:
Assert.That(GetType(), Has.Attribute<Attr1>() | Has.Attribute<Attr2>());

Compiler gives an error like "cannot use operator | with two ResolvableConstraintExpressions".
Would be nice if this will compile in future.

But this works:
Assert.That(GetType(), Has.Attribute<Attr1>().Or.Attribute<Attr2>());

Related branches

Changed in nunitv2:
status: New → Triaged
importance: Undecided → Medium
Revision history for this message
Rechenelf (matklaus) wrote :

After thinking about once again, I wundering why | (bitwise or) is used instead of || (boolean or).
Should not be the operator|| be overloaded instead of operator|?
Similar && instead of &.

Revision history for this message
Charlie Poole (charlie.poole) wrote :

The design of NUnit requires the operator to return a constraint object, combining the two constraints. This is not possible using logical or, since || cannot be overridden. It's possible to simulate an override of operator ||, by specifying an implicit conversion of the constraint to boolean, but that would give a boolean result rather than a constraint. We need a constraint because the constraint object knows how to provide an error message.

Changed in nunitv2:
assignee: nobody → Charlie Poole (charlie.poole)
milestone: none → 2.6.1
Revision history for this message
Charlie Poole (charlie.poole) wrote :

Also applies to operator & and operator ! overrides. For the binary operators, it also needed combinations of Constraint and ResolvableConstraintExpression in both orders.

Changed in nunitv2:
status: Triaged → Fix Committed
Changed in nunitv2:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.