Forums
cannot use int.maxValue
10 posts
• Page 1 of 1
cannot use int.maxValue
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
One more thing. How do I test if a dynamic object is > 0?
I've tried the following but it fails at runtime (ArgumentException):
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
One more thing. Hope this doesn't get annoying.
Is is normal that the following fails to compile?
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.
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
Ultimately, the Cobra run-time for "x > 0" is invoking:
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.
(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
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.
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
I think I found another bug:
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.
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
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
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
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) ...
- Charles
- Posts: 2515
- Location: Los Angeles, CA
Re: cannot use int.maxValue
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
10 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 44 guests