Skip to main content



      Home
Home » Modeling » EMF » [Xcore] Something wrong with casts?
[Xcore] Something wrong with casts? [message #1240451] Thu, 06 February 2014 08:48 Go to next message
Eclipse UserFriend
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 Go to previous messageGo to next message
Eclipse UserFriend
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 Go to previous messageGo to next message
Eclipse UserFriend
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 Go to previous message
Eclipse UserFriend
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.
Previous Topic:[CDO] open a client session when running a security manager
Next Topic:[xcore] Implement method outside of xcore model
Goto Forum:
  


Current Time: Thu Mar 27 03:59:12 EDT 2025

Powered by FUDForum. Page generated in 0.04125 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top