Page 1 of 1

Decimal Literal

PostPosted: Mon Dec 06, 2010 3:39 pm
by torial
I have found that when trying to declare a decimal literal, such as -100000000d, I get an error: 'Expecting EOL, but got "d" (ID) instead.' This is easily resolved by adding a period and a zero: -100000000.0d

Despite there being an easy resolution, I'm unsure why it is required to have a .0 for decimal literals. Given that Cobra is very smart about figuring many other things out, why isn't it smart enough to treat it as a decimal w/o choking? Is this something I should write a bug for, or is it WAD?

Re: Decimal Literal

PostPosted: Mon Dec 06, 2010 3:42 pm
by Charles
I can't think of any problems with whole number literals having suffixes like d, f32, f64 and f to set their type. Any objections?

Should we also have "n" for "number" which is a type in Cobra?

Re: Decimal Literal

PostPosted: Tue Dec 07, 2010 12:36 am
by todd.a
We definitely need one for byte/uint8. Will come in handy for byte arrays.

Re: Decimal Literal

PostPosted: Tue Dec 07, 2010 3:13 am
by Charles
We already have that covered:
x = 5u8
trace x
# outputs:
# trace: x=5 (Byte); at ...

Re: Decimal Literal

PostPosted: Tue Dec 07, 2010 8:09 am
by todd.a
Ah, sweet.

Re: Decimal Literal

PostPosted: Tue Dec 07, 2010 8:41 am
by torial
I love the idea of "n" for number.

Re: Decimal Literal

PostPosted: Tue Dec 07, 2010 9:17 pm
by Charles
Done in changeset:2467:

Support numeric literals like `45n` for `number` and `45d` for decimal. Previously, the `d` suffix required a decimal portion (`45.0d`) and there was no `n` suffix available.
reported-by:torial


Please test it and let me know how it goes.

Re: Decimal Literal

PostPosted: Thu Dec 09, 2010 3:27 am
by hopscc
It seems since that patch the cobra tests fail - specifically Tests/110-basics-two/110-int-types.cobra
Code: Select all


RUN ..\Tests\110-basics-two\110-int-types.cobra
    C:\home\hops\src\cobra\wkspace1\Source\..\Tests\110-basics-two\110-int-types.cobra
    Test #1
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
Skipping duplicate message: c:\home\hops\src\cobra\wkspace1\Tests\tests\110-basics-two\110-int-types.cobra(185): error: The call is ambiguous between the following methods or properties: "Cobra.Lang.CobraImp.IsTrue(float?)" and "Cobra.Lang.CobraImp.IsTrue(decimal?)" (C#)
Skipping duplicate message: c:\home\hops\src\cobra\wkspace1\Tests\tests\110-basics-two\110-int-types.cobra(187): error: The call is ambiguous between the following methods or properties: "Cobra.Lang.CobraImp.IsTrue(float?)" and "Cobra.Lang.CobraImp.IsTrue(decimal?)" (C#)
Skipping duplicate message: c:\home\hops\src\cobra\wkspace1\Tests\tests\110-basics-two\110-int-types.cobra(219): error: The call is ambiguous between the following methods or properties: "Cobra.Lang.CobraImp.IsTrue(float?)" and "Cobra.Lang.CobraImp.IsTrue(decimal?)" (C#)
Skipping duplicate message: c:\home\hops\src\cobra\wkspace1\Tests\tests\110-basics-two\110-int-types.cobra(221): error: The call is ambiguous between the following methods or properties: "Cobra.Lang.CobraImp.IsTrue(float?)" and "Cobra.Lang.CobraImp.IsTrue(decimal?)" (C#)
Skipping duplicate message: c:\home\hops\src\cobra\wkspace1\Tests\tests\110-basics-two\110-int-types.cobra(236): error: The call is ambiguous between the following methods or properties: "Cobra.Lang.CobraImp.IsTrue(float?)" and "Cobra.Lang.CobraImp.IsTrue(decimal?)" (C#)
Skipping duplicate message: c:\home\hops\src\cobra\wkspace1\Tests\tests\110-basics-two\110-int-types.cobra(238): error: The call is ambiguous between the following methods or properties: "Cobra.Lang.CobraImp.IsTrue(float?)" and "Cobra.Lang.CobraImp.IsTrue(decimal?)" (C#)
Skipping duplicate message: c:\home\hops\src\cobra\wkspace1\Tests\tests\110-basics-two\110-int-types.cobra(253): error: The call is ambiguous between the following methods or properties: "Cobra.Lang.CobraImp.IsTrue(float?)" and "Cobra.Lang.CobraImp.IsTrue(decimal?)" (C#)
Skipping duplicate message: c:\home\hops\src\cobra\wkspace1\Tests\tests\110-basics-two\110-int-types.cobra(255): error: The call is ambiguous between the following methods or properties: "Cobra.Lang.CobraImp.IsTrue(float?)" and "Cobra.Lang.CobraImp.IsTrue(decimal?)" (C#)
c:\home\hops\src\cobra\wkspace1\Tests\tests\110-basics-two\110-int-types.cobra(185): error: The call is ambiguous between the following methods or properties: "Cobra.Lang.CobraImp.IsTrue(float?)" and "Cobra.Lang.CobraImp.IsTrue(decimal?)" (C#)
c:\home\hops\src\cobra\wkspace1\Tests\tests\110-basics-two\110-int-types.cobra(187): error: The call is ambiguous between the following methods or properties: "Cobra.Lang.CobraImp.IsTrue(float?)" and "Cobra.Lang.CobraImp.IsTrue(decimal?)" (C#)
c:\home\hops\src\cobra\wkspace1\Tests\tests\110-basics-two\110-int-types.cobra(189): error: The call is ambiguous between the following methods or properties: "Cobra.Lang.CobraImp.IsTrue(float?)" and "Cobra.Lang.CobraImp.IsTrue(decimal?)" (C#)
c:\home\hops\src\cobra\wkspace1\Tests\tests\110-basics-two\110-int-types.cobra(219): error: The call is ambiguous between the following methods or properties: "Cobra.Lang.CobraImp.IsTrue(float?)" and "Cobra.Lang.CobraImp.IsTrue(decimal?)" (C#)
c:\home\hops\src\cobra\wkspace1\Tests\tests\110-basics-two\110-int-types.cobra(221): error: The call is ambiguous between the following methods or properties: "Cobra.Lang.CobraImp.IsTrue(float?)" and "Cobra.Lang.CobraImp.IsTrue(decimal?)" (C#)
c:\home\hops\src\cobra\wkspace1\Tests\tests\110-basics-two\110-int-types.cobra(223): error: The call is ambiguous between the following methods or properties: "Cobra.Lang.CobraImp.IsTrue(float?)" and "Cobra.Lang.CobraImp.IsTrue(decimal?)" (C#)
c:\home\hops\src\cobra\wkspace1\Tests\tests\110-basics-two\110-int-types.cobra(236): error: The call is ambiguous between the following methods or properties: "Cobra.Lang.CobraImp.IsTrue(float?)" and "Cobra.Lang.CobraImp.IsTrue(decimal?)" (C#)
c:\home\hops\src\cobra\wkspace1\Tests\tests\110-basics-two\110-int-types.cobra(238): error: The call is ambiguous between the following methods or properties: "Cobra.Lang.CobraImp.IsTrue(float?)" and "Cobra.Lang.CobraImp.IsTrue(decimal?)" (C#)
c:\home\hops\src\cobra\wkspace1\Tests\tests\110-basics-two\110-int-types.cobra(240): error: The call is ambiguous between the following methods or properties: "Cobra.Lang.CobraImp.IsTrue(float?)" and "Cobra.Lang.CobraImp.IsTrue(decimal?)" (C#)
c:\home\hops\src\cobra\wkspace1\Tests\tests\110-basics-two\110-int-types.cobra(242): error: The call is ambiguous between the following methods or properties: "Cobra.Lang.CobraImp.IsTrue(float?)" and "Cobra.Lang.CobraImp.IsTrue(decimal?)" (C#)
c:\home\hops\src\cobra\wkspace1\Tests\tests\110-basics-two\110-int-types.cobra(253): error: The call is ambiguous between the following methods or properties: "Cobra.Lang.CobraImp.IsTrue(float?)" and "Cobra.Lang.CobraImp.IsTrue(decimal?)" (C#)
c:\home\hops\src\cobra\wkspace1\Tests\tests\110-basics-two\110-int-types.cobra(255): error: The call is ambiguous between the following methods or properties: "Cobra.Lang.CobraImp.IsTrue(float?)" and "Cobra.Lang.CobraImp.IsTrue(decimal?)" (C#)
c:\home\hops\src\cobra\wkspace1\Tests\tests\110-basics-two\110-int-types.cobra(257): error: The call is ambiguous between the following methods or properties: "Cobra.Lang.CobraImp.IsTrue(float?)" and "Cobra.Lang.CobraImp.IsTrue(decimal?)" (C#)
Compilation failed - 13 errors, 0 warnings
----------------------------------------------------------------------------------------------------


Re: Decimal Literal

PostPosted: Thu Dec 09, 2010 3:36 am
by Charles
Did you do a "cobra -bsl" to produce a new Cobra.Lang.dll? I think this is the problem.

Re: Decimal Literal

PostPosted: Thu Dec 09, 2010 3:54 am
by hopscc
My apologies, so it is