[nem-en] Re: conversion of int to uint

Valient Gough valient at gmail.com
Thu Feb 23 18:19:46 CET 2006


On 2/22/06, Michal Moskal <michal.moskal at gmail.com> wrote:
> On 2/23/06, Valient Gough <valient at gmail.com> wrote:
> > 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)

Ahhh.. That's where I was going wrong, I didn't have the "!= 0" to
explicitly test against 0 and convert to type boolean.

>
> 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?

Well, I did try lots of different ways.  So here is a standalone example:

> cat test.n
class Foo
{
    modes_ : uint;
    access(mask : int) : int
    {
        def checkMask( mask, modes )
        {
            if(((mask :> uint) %& modes) != 0)
                0;
            else
                -1;
        }
        checkMask( mask, modes_ );
    }
}

> ncc --version
Nemerle Compiler (ncc) version 0.9.2 (release)
(c) 2003-2005 University of Wroclaw, All rights reserved.

> ncc -o test.dll test.n
test.n:13:1:13:10: error: in argument #1 (mask), needed a
System.UInt32-, got int: 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
test.n:13:1:13:10: error: typing error in call

Line 13 is the checkMask() call.
But this sample is very close to working (since it has the "!= 0"
test).  The second error hints at the real reason - it needs the
checkMask definition changed to "def checkMask( mask : int , modes )".
  But the reason I never got that far is because of the missing !=0
test.  I must have been doing too much C++ programming lately to
forget that.

thanks,
Valient



More information about the devel-en mailing list