Forums

bitwise operator with enum?

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

bitwise operator with enum?

Postby gauthier » Sun Dec 07, 2008 10:49 pm

I'm getting error trying to use bitwise operator on combined enum values:
enum Borders
Top = 1
Right = 2
Bottom = 4
Left = 8

class Test
def main is shared
borders = Borders(Top,Left)
assert (borders & Borders.Top) == Borders.Top


Code: Select all
test.cobra(10): error: Cannot apply AMPERSAND to Borders. Try finding a method that performs this function.
Compilation failed - 1 error, 0 warnings


is there any support for bitwise operators on enum without casting every operand to int?
gauthier
 
Posts: 116

Re: bitwise operator with enum?

Postby Charles » Sun Dec 07, 2008 11:51 pm

Hmm, it looks like when I implemented the bitwise operators, I did them for ints, but not enums. Sorry about that. For now you will have to use casts.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: bitwise operator with enum?

Postby Charles » Mon Dec 08, 2008 12:29 am

Fixed, tested and checked in.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: bitwise operator with enum?

Postby gauthier » Mon Dec 08, 2008 12:34 am

Thanks!

the fix is a pretty small delta :)
gauthier
 
Posts: 116

Re: bitwise operator with enum?

Postby Charles » Mon Dec 08, 2008 12:39 am

Well I probably inadvertently allowed "enum + enum" and "enum * enum" but this quick fix is the lesser of two evils.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: bitwise operator with enum?

Postby gauthier » Mon Dec 08, 2008 12:45 am

Can you point me to a sample of compiler unit test that check for expected message? (a beginner one)
gauthier
 
Posts: 116

Re: bitwise operator with enum?

Postby Charles » Mon Dec 08, 2008 1:43 am

<workspace>\Tests\100-basics\402-branch.cobra

which tests a parsing error. Not that the type of error really matters.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: bitwise operator with enum?

Postby gauthier » Mon Dec 08, 2008 1:57 am

Is there a way to run the testfixtures asserting on theses compilator errors?
gauthier
 
Posts: 116

Re: bitwise operator with enum?

Postby Charles » Mon Dec 08, 2008 2:06 am

I'm not entirely sure what you're asking.

You can verify that Cobra generates an error with the # .error. directive in the test cases. If the compiler fails to generate an error, then that test will fail. If the error takes place with the given substring included, then the test passes.

See also:

-- <workspace>\Developer\ImplementationNotes.text. Look for "testify".

-- See also "Test Cases" at HowToSubmitAPatch.

-- The implementation is in TestifyRunner.cobra. Although hopefully you don't have to read that just to make new test cases.

If that does not answer your question, let me know.
Charles
 
Posts: 2515
Location: Los Angeles, CA


Return to Discussion

Who is online

Users browsing this forum: No registered users and 104 guests

cron