Page 1 of 1

cannot use int.maxValue

PostPosted: Thu Jan 15, 2009 10:08 am
by jonathandavid
Or uint.minValue, or any other property of that kind. I can easily find a work around, so this is not an urgent thing.

Re: cannot use int.maxValue

PostPosted: Thu Jan 15, 2009 12:42 pm
by jonathandavid
One more thing. How do I test if a dynamic object is > 0?

I've tried the following but it fails at runtime (ArgumentException):

class Program

def isPositive(x as dynamic) as bool is shared
return x > 0

def main is shared
print .isPositive(3f)

Re: cannot use int.maxValue

PostPosted: Thu Jan 15, 2009 1:03 pm
by jonathandavid
One more thing. Hope this doesn't get annoying.

Is is normal that the following fails to compile?

extend String
def func1
pass

extend String
def func2
pass

class Program
def main is shared
pass


Apparently, the second time "extend String" appears, Cobra generates some boiler plate code in which a name clashes with the code it had generated during the first "extend String". I have a workaround for this too (you guessed it, combine to both "extends" into a single one). But I thought it might be interesting to report it nevertheless.

Re: cannot use int.maxValue

PostPosted: Thu Jan 15, 2009 1:52 pm
by Charles
Ultimately, the Cobra run-time for "x > 0" is invoking:
(a to IComparable).compareTo(b)

And it is System.Double.CompareTo that is choking on the integer. I wish it wouldn't. I've enhanced the code to promote the integer when needed and checked in the fix.

Regarding your "extend" problem, I was aware of it, but just hadn't gotten to fixing that yet. Sorry you ran into it.

No annoyances here. I need to hear about all problems so they can be fixed and locked out with test cases.

Re: cannot use int.maxValue

PostPosted: Thu Jan 15, 2009 2:00 pm
by jonathandavid
Thanks for answering. Did you read my first question, the one about uint.minValue?

BTW I have the Prompt class mostly sorted out. I'll post it here tomorrow. I've made some bold design decisions, I'm eager to see what everyone thinks about them.

Re: cannot use int.maxValue

PostPosted: Thu Jan 15, 2009 4:35 pm
by jonathandavid
I think I found another bug:

class G<of T>

var myT as T


class Program

var g = G<of int?>()

def main is shared
p = Program()


This triggers a runtime assertion, complaining that myT is nil. It is as if the compiler did not realize that T is taking the value int?, and that therefore "myT" should be allowed to be nil.

Re: cannot use int.maxValue

PostPosted: Fri Jan 16, 2009 3:24 am
by jonathandavid
Chuck wrote:I've enhanced the code to promote the integer when needed and checked in the fix.


Thanks. Is there another way to obtain a zero converted to the type of "x"?

I'm thinking of something along the lines of:

def isPositive(x as dynamic) as bool is shared
zero = 0 to x.type
return x > zero

Re: cannot use int.maxValue

PostPosted: Fri Jan 16, 2009 3:25 am
by Charles
jonathandavid wrote:I think I found another bug:

class G<of T>

var myT as T


class Program

var g = G<of int?>()

def main is shared
p = Program()


This triggers a runtime assertion, complaining that myT is nil. It is as if the compiler did not realize that T is taking the value int?, and that therefore "myT" should be allowed to be nil.

Looks like a bug. Can you add a ticket?

Re: cannot use int.maxValue

PostPosted: Fri Jan 16, 2009 3:28 am
by Charles
jonathandavid wrote:
Chuck wrote:I've enhanced the code to promote the integer when needed and checked in the fix.


Thanks. Is there another way to obtain a zero converted to the type of "x"?

I'm thinking of something along the lines of:

def isPositive(x as dynamic) as bool is shared
zero = 0 to x.type
return x > zero

Yes, .NET comes with a Convert utility class. You can say:
Convert.changeType(0, x.getType)

Although for your specific example, there's no benefit as Cobra will now do this for you when dealing with dynamic values.

Also, dynamic is the default type for arguments so you can just say:
def foo(a, b) ...
if you like.

Re: cannot use int.maxValue

PostPosted: Tue Jan 27, 2009 4:09 am
by jonathandavid
Chuck wrote:Looks like a bug. Can you add a ticket?


Added. I've also added another one for the int.maxValue issue.