[nem-en] Re: conversion of int to uint
Michal Moskal
michal.moskal at gmail.com
Thu Feb 23 08:53:50 CET 2006
On 2/23/06, Valient Gough <valient at gmail.com> wrote:
> Hi,
>
> I'm having trouble converting from an int to uint. I have to convert
> to a common type because I need to apply a bit-field operation, and
> I'm constrained on the different types from external interfaces.
>
> My expectation was for something like this to work:
>
> def checkMask( mask, modes )
> {
> if((mask :> uint) %& modes)
> 0;
> else
> ErrorCode.EACCES;
> }
>
> But that gives an error "System.Int32 is not a subtype of
> System.UInt32 [simple require]"
I guess the problem is that you need to write:
if((mask :> uint) %& modes != 0)
There are two options:
- either you pasted something else than you have in your sources
- or there is some bug in the compiler that makes it produce such
junky error messages
Maybe you can post a self-contained example?
> So I searched around the nemerle site and didn't see anything. I tried
> other variations without success, and then I tried casting the uints
> to ints and got an interesting error: "common super type of types
> [System.UInt32, int] is just `System.ValueType', please upcast one of
> the types to `System.ValueType' if this is desired
> "
We thought this would be hit mostly for System.Object, not
System.ValueType, where it makes more sense.
> So, I tried to force a conversion through ValueType:
>
> def checkMask( mask : ValueType , modes )
> {
> if((mask :> uint) %& modes)
> ...
>
> That resulted in an ICE:
> error: internal compiler error: assertion failed in file
> generation/ILEmitter.n, line 778:
> Sulf.GenericNode::Access: failed to convert non-value type
> System.ValueType to a value type System.UInt32
This is an ICE on invalid code, so not that critical, but still a bug
that needs to be fixed, so please report.
--
Michal Moskal,
http://nemerle.org/~malekith/
More information about the devel-en
mailing list