Forums

cannot use int.maxValue

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

cannot use int.maxValue

Postby jonathandavid » Thu Jan 15, 2009 10:08 am

Or uint.minValue, or any other property of that kind. I can easily find a work around, so this is not an urgent thing.
jonathandavid
 
Posts: 159

Re: cannot use int.maxValue

Postby jonathandavid » Thu Jan 15, 2009 12:42 pm

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)
jonathandavid
 
Posts: 159

Re: cannot use int.maxValue

Postby jonathandavid » Thu Jan 15, 2009 1:03 pm

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.
jonathandavid
 
Posts: 159

Re: cannot use int.maxValue

Postby Charles » Thu Jan 15, 2009 1:52 pm

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.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: cannot use int.maxValue

Postby jonathandavid » Thu Jan 15, 2009 2:00 pm

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.
jonathandavid
 
Posts: 159

Re: cannot use int.maxValue

Postby jonathandavid » Thu Jan 15, 2009 4:35 pm

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.
jonathandavid
 
Posts: 159

Re: cannot use int.maxValue

Postby jonathandavid » Fri Jan 16, 2009 3:24 am

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
jonathandavid
 
Posts: 159

Re: cannot use int.maxValue

Postby Charles » Fri Jan 16, 2009 3:25 am

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?
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: cannot use int.maxValue

Postby Charles » Fri Jan 16, 2009 3:28 am

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.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: cannot use int.maxValue

Postby jonathandavid » Tue Jan 27, 2009 4:09 am

Chuck wrote:Looks like a bug. Can you add a ticket?


Added. I've also added another one for the int.maxValue issue.
jonathandavid
 
Posts: 159


Return to Discussion

Who is online

Users browsing this forum: No registered users and 67 guests