Skip to content

Commit

Permalink
Prefer user operators over predefined operators for binary enum opera…
Browse files Browse the repository at this point in the history
…tions too. Fixes #13202
  • Loading branch information
marek-safar committed Jul 12, 2013
1 parent 035214b commit 479cfc6
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 5 deletions.
11 changes: 6 additions & 5 deletions mcs/mcs/expression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2752,6 +2752,12 @@ public Expression ResolveOperator (ResolveContext rc)
if (l.IsPointer || r.IsPointer)
return ResolveOperatorPointer (rc, l, r);

// User operators
expr = ResolveUserOperator (rc, left, right);
if (expr != null)
return expr;


bool lenum = l.IsEnum;
bool renum = r.IsEnum;
if ((oper & (Operator.ComparisonMask | Operator.BitwiseMask)) != 0) {
Expand Down Expand Up @@ -2805,11 +2811,6 @@ public Expression ResolveOperator (ResolveContext rc)
return expr;
}
}

// User operators
expr = ResolveUserOperator (rc, left, right);
if (expr != null)
return expr;
}

//
Expand Down
39 changes: 39 additions & 0 deletions mcs/tests/test-869.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;

public class C
{
public static readonly C Token = new C ();

public static C operator & (C set, E value)
{
return Token;
}

public static implicit operator E (C c)
{
throw new ApplicationException ();
}
}

public enum E
{
Item = 2
}

class FooClass
{
public static int Main ()
{
C m = new C ();
var x = E.Item;
var res = m & x;
if (res != C.Token)
return 1;

res = m & E.Item;
if (res != C.Token)
return 2;

return 0;
}
}
24 changes: 24 additions & 0 deletions mcs/tests/ver-il-net_4_5.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47544,6 +47544,30 @@
</method>
</type>
</test>
<test name="test-869.cs">
<type name="C">
<method name="C op_BitwiseAnd(C, E)" attrs="2198">
<size>14</size>
</method>
<method name="E op_Implicit(C)" attrs="2198">
<size>7</size>
</method>
<method name="Void .ctor()" attrs="6278">
<size>7</size>
</method>
<method name="Void .cctor()" attrs="6289">
<size>11</size>
</method>
</type>
<type name="FooClass">
<method name="Int32 Main()" attrs="150">
<size>70</size>
</method>
<method name="Void .ctor()" attrs="6278">
<size>7</size>
</method>
</type>
</test>
<test name="test-87.cs">
<type name="Top">
<method name="Int32 Main()" attrs="150">
Expand Down

0 comments on commit 479cfc6

Please sign in to comment.