bugDotGNU Portable.NET - Bugs: bug #1006, Coerce 0 to enum

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #1006: Coerce 0 to enum

Submitted by:  Jonathan Springer <springjp>
Submitted on:  Fri 16 Aug 2002 11:14:39 AM UTC  
 
Category: NoneSeverity: 3 - Normal
Item Group: NoneStatus: Fixed
Privacy: PublicAssigned to: None
Open/Closed: Closed

Tue 10 Sep 2002 12:39:12 AM UTC, comment #1:

Fixed in the CVS version, 10 September 2002.

Rhys Weatherley <rweather>
Project Administrator
Fri 16 Aug 2002 11:14:39 AM UTC, original submission:

This code:

<SNIP>
using System;

[Flags]
public enum AttrEnum {
attr0 = 0x0001
}

public class ConcreteAttrClass {
private AttrEnum a;
public AttrEnum Attr { get { return a; } }

public ConcreteAttrClass() { a = 0; }

public void SetAttr0() { a = AttrEnum.attr0; }

public static void Main() {
ConcreteAttrClass x = new ConcreteAttrClass();
if (x.Attr == 0) {
Console.WriteLine("Starts out as 0.");
} else {
Console.WriteLine("Starts out non-zero(?)");
}
x.SetAttr0();
if ((x.Attr & AttrEnum.attr0) != 0) {
Console.WriteLine("Attribute set successfully.");
} else {
Console.WriteLine("Attribute not set successfully.");
}
}
}
</SNIP>

Gives the following compile errors:
concreteenum.cs:18: invalid operands to binary `=='
concreteenum.cs:18: no conversion from `int' to `bool'
concreteenum.cs:24: invalid operands to binary `!='
concreteenum.cs:24: no conversion from `int' to `bool'

My "C# In a Nutshell" says literal 0 can be coerced to enum. This code is similar to many of the current compile failures in libpnet.

Jonathan Springer <springjp>
Project Member

 

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

CC list is empty

 

Do you think this task is very important?
If so, you can click here to add your encouragement to it.
This task has 0 encouragements so far.

Only logged-in users can vote.

 

Please enter the title of George Orwell's famous dystopian book (it's a date):

 

 

Follow 3 latest changes.

Date Changed By Updated Field Previous Value => Replaced By
Tue 10 Sep 2002 12:39:12 AM UTCrweatherStatusNone=>(Error - Not Found)
  Open/ClosedOpen=>(Error - Not Found)
  Closed on-=>-

Back to the top


Powered by Savane 3.1-cleanup1