|
Re: [Xcore] Something wrong with casts? [message #1240977 is a reply to message #1240451] |
Fri, 07 February 2014 09:43 |
Ed Merks Messages: 33210 Registered: July 2009 |
Senior Member |
|
|
Phillip,
Comments below.
On 06/02/2014 2:48 PM, Phillip Keldenich wrote:
> Hey, for the lack of documentation stating that casts do very strange
> things in xcore, I believe this is a bug:
>
> package test
>
> //import java.lang.Double // - these are not important
> //type Double wraps Double // - problem occurs with and without these lines
>
> class Test {
> op Double test(Object obj) {
> if(obj instanceof Double) {
> return (Double)obj // gives an error about
> // being unable to convert from Class<Double> to Double ?
> } else {
> return new Double(0.0)
> }
> }
> }
>
> Is this known?
This is more of an Xbase question. With Xbase casting is done with
using "as", i.e., "obj as Double". But if you try that, you'll notice
it warns you that the cast is unnecessary. Xbase knows obj must be of
type Double in that context. How smart is that? :-P
> How does one workaround this?
> If this is the desired behaviour, how does one perform casts properly?
>
> Cheers,
> Phillip
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: [Xcore] Something wrong with casts? [message #1244134 is a reply to message #1240977] |
Wed, 12 February 2014 00:00 |
Phillip Keldenich Messages: 9 Registered: January 2014 |
Junior Member |
|
|
Am 07.02.2014 10:43, schrieb Ed Merks:
> Phillip,
>
> Comments below.
>
> On 06/02/2014 2:48 PM, Phillip Keldenich wrote:
>> Hey, for the lack of documentation stating that casts do very strange
>> things in xcore, I believe this is a bug:
>>
>> package test
>>
>> //import java.lang.Double // - these are not important
>> //type Double wraps Double // - problem occurs with and without these
>> lines
>>
>> class Test {
>> op Double test(Object obj) {
>> if(obj instanceof Double) {
>> return (Double)obj // gives an error about
>> // being unable to convert from Class<Double> to Double ?
>> } else {
>> return new Double(0.0)
>> }
>> }
>> }
>>
>> Is this known?
> This is more of an Xbase question. With Xbase casting is done with
> using "as", i.e., "obj as Double". But if you try that, you'll notice
> it warns you that the cast is unnecessary. Xbase knows obj must be of
> type Double in that context. How smart is that? :-P
>> How does one workaround this?
>> If this is the desired behaviour, how does one perform casts properly?
>>
>> Cheers,
>> Phillip
>
Thank you. Using "as" works.
The automatic detection however doesn't.
|
|
|
Re: [Xcore] Something wrong with casts? [message #1244317 is a reply to message #1244134] |
Wed, 12 February 2014 06:48 |
Ed Merks Messages: 33210 Registered: July 2009 |
Senior Member |
|
|
Phillip,
I think the automatic detection is new to Xtext 2.5.1 (or maybe new to
the ongoing 2.6 development), i.e., it's a new feature of Xbase.
On 12/02/2014 1:00 AM, Phillip Keldenich wrote:
> Am 07.02.2014 10:43, schrieb Ed Merks:
>> Phillip,
>>
>> Comments below.
>>
>> On 06/02/2014 2:48 PM, Phillip Keldenich wrote:
>>> Hey, for the lack of documentation stating that casts do very strange
>>> things in xcore, I believe this is a bug:
>>>
>>> package test
>>>
>>> //import java.lang.Double // - these are not important
>>> //type Double wraps Double // - problem occurs with and without these
>>> lines
>>>
>>> class Test {
>>> op Double test(Object obj) {
>>> if(obj instanceof Double) {
>>> return (Double)obj // gives an error about
>>> // being unable to convert from Class<Double> to Double ?
>>> } else {
>>> return new Double(0.0)
>>> }
>>> }
>>> }
>>>
>>> Is this known?
>> This is more of an Xbase question. With Xbase casting is done with
>> using "as", i.e., "obj as Double". But if you try that, you'll notice
>> it warns you that the cast is unnecessary. Xbase knows obj must be of
>> type Double in that context. How smart is that? :-P
>>> How does one workaround this?
>>> If this is the desired behaviour, how does one perform casts properly?
>>>
>>> Cheers,
>>> Phillip
> Thank you. Using "as" works.
> The automatic detection however doesn't.
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.04751 seconds