[Mono-bugs] [Bug 687576] New: error CS0019: Operator `==' cannot be applied to operands of type `NullableId' and `int? '
bugzilla_noreply at novell.com
bugzilla_noreply at novell.com
Thu Apr 14 11:47:38 EDT 2011
https://bugzilla.novell.com/show_bug.cgi?id=687576
https://bugzilla.novell.com/show_bug.cgi?id=687576#c0
Summary: error CS0019: Operator `==' cannot be applied to
operands of type `NullableId' and `int? '
Classification: Mono
Product: Mono: Compilers
Version: 2.10.x
Platform: x86
OS/Version: Ubuntu
Status: NEW
Severity: Major
Priority: P5 - None
Component: C#
AssignedTo: msafar at novell.com
ReportedBy: bblinn at gmail.com
QAContact: mono-bugs at lists.ximian.com
Found By: Customer
Blocker: ---
Description of Problem:
The following code produces the error in the title when attempting to compile
using xbuild:
public class NullableId
{
private int? m_value;
public NullableId(int? value)
{
m_value = value;
}
public NullableId()
{
m_value = 0;
}
public int? Value
{
get { return m_value; }
set { m_value = value; }
}
public override bool Equals(object obj)
{
return (obj is NullableId && m_value == ((NullableId)obj).m_value);
}
public override int GetHashCode()
{
return m_value.GetHashCode();
}
public override string ToString()
{
return m_value.HasValue ? m_value.ToString() : "null";
}
public static implicit operator int?(NullableId val)
{
return val.m_value;
}
public static implicit operator NullableId(int? val)
{
return new NullableId(val);
}
public static implicit operator IdWrapper(NullableId val)
{
return val.m_value.HasValue ? new IdWrapper(val.m_value.Value) :
IdWrapper.Invalid;
}
public static implicit operator NullableId(int val)
{
return new NullableId(val);
}
}
public struct IdWrapper
{
public static readonly IdWrapper Invalid = new IdWrapper(0);
private int m_value;
public IdWrapper(int value)
{
m_value = value;
}
public int Value
{
get { return m_value; }
set { m_value = value; }
}
public override bool Equals(object obj)
{
return (obj is IdWrapper && m_value == ((IdWrapper)obj).m_value);
}
public override int GetHashCode()
{
return m_value.GetHashCode();
}
public override string ToString()
{
return (m_value).ToString();
}
public static implicit operator int(IdWrapper val)
{
return val.m_value;
}
public static implicit operator IdWrapper(int val)
{
return new IdWrapper(val);
}
public static implicit operator NullableId(IdWrapper val)
{
return new NullableId { Value = val.m_value };
}
}
public class Foo
{
public NullableId Id { get; set; }
public IdWrapper OtherId { get; set; }
public static Foo Convert(Bar bar)
{
return new Foo { OtherId = bar.OtherId, Id = bar.Id };
}
public static bool Compare (Foo foo, Bar bar)
{
return foo.Id == bar.Id && foo.OtherId == bar.OtherId;
}
public bool Equals(object obj)
{
var other = obj as Foo;
if (other != null)
return other.Id == Id && other.OtherId == OtherId;
return false;
}
}
public class Bar
{
public int? Id { get; set; }
public int OtherId { get; set; }
public static Bar Convert(Foo foo)
{
return new Bar { OtherId = foo.OtherId, Id = foo.Id };
}
}
Steps to reproduce the problem:
1. Add the code to a file
2. Compile using xbuild
Actual Results:
error CS0019: Operator `==' cannot be applied to operands of type `NullableId'
and `int? '
Expected Results:
Success - it works in MSVC.
How often does this happen?
All the time
Additional Information:
There is also another error that I could not reliably reproduce with a simple
test case, but seems related. The output was this:
error CS0266: Cannot implicitly convert type `int?' to `NullableID'. An
explicit conversion exists (are you missing a cast?)
And it happened when assigning an int? value from one object to a NullableId
value on another object.
--
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
More information about the mono-bugs
mailing list