Watch, Follow, &
Connect with Us

Please visit our new home
community.embarcadero.com.

Public Report
Report From: Delphi Prism/Compiler    [ Add a report in this area ]  
Report #:  88923   Status: Open
Set equality operator does not work
Project:  Embarcadero Prism Build #:  4.0.25.791
Version:    1.1 Submitted By:   Robert Ogren
Report Type:  Basic functionality failure Date Reported:  10/13/2010 5:46:13 AM
Severity:    Critical / Show Stopper Last Updated: 3/20/2012 2:24:39 AM
Platform:    All platforms Internal Tracking #:   280833
Resolution: None (Resolution Comments) Resolved in Build: : None
Duplicate of:  None
Voting and Rating
Overall Rating: No Ratings Yet
0.00 out of 5
Total Votes: None
Description
The set equality and inequality operators do not seem to work in Delphi Prism XE. When I run simple code like this, the sets are not considered equal.

type MyAttribute = (
    AttributeA,
    AttributeB
  );
  MyAttributes = set of MyAttribute;
  
...
  var a: MyAttributes := [MyAttribute.AttributeA];

  if a = [MyAttribute.AttributeA] then
    Console.WriteLine('Equality test succeeds')
  else
    Console.WriteLine('Equality test fails');

As far as I can see, this is a bug in <PublicImplementationDetails>+Set<T>.op_Equality

According to Reflector the comparison of the array elements looks like this:
          if (((num >= a.fValue.Length) ? 0 : a.fValue) != ((num >= b.fValue.Length) ? 0 : b.fValue))

instead of this:

          if (((num >= a.fValue.Length) ? 0 : a.fValue[num]) != ((num >= b.fValue.Length) ? 0 : b.fValue[num]))

I.e. it compares the array references instead of the actual elements.
Steps to Reproduce:
Compile and run the attached sample program, and watch the output. I expect it to say 'Equality test succeeds' but it does not.
Workarounds
None
Attachment
88923.zip
Comments

None

Server Response from: ETNACODE01