[Xcore] Something wrong with casts? [message #1240451] |
Thu, 06 February 2014 08:48  |
Eclipse User |
|
|
|
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?
How does one workaround this?
If this is the desired behaviour, how does one perform casts properly?
Cheers,
Phillip
|
|
|
Re: [Xcore] Something wrong with casts? [message #1240977 is a reply to message #1240451] |
Fri, 07 February 2014 04:43   |
Eclipse User |
|
|
|
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
|
|
|
Re: [Xcore] Something wrong with casts? [message #1244134 is a reply to message #1240977] |
Tue, 11 February 2014 19:00   |
Eclipse User |
|
|
|
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 01:48  |
Eclipse User |
|
|
|
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.
|
|
|
Powered by
FUDForum. Page generated in 0.04125 seconds