Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [Xcore] Something wrong with casts?
[Xcore] Something wrong with casts? [message #1240451] Thu, 06 February 2014 13:48 Go to next message
Phillip Keldenich is currently offline Phillip KeldenichFriend
Messages: 9
Registered: January 2014
Junior Member
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 09:43 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30688
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
Re: [Xcore] Something wrong with casts? [message #1244134 is a reply to message #1240977] Wed, 12 February 2014 00:00 Go to previous messageGo to next message
Phillip Keldenich is currently offline Phillip KeldenichFriend
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 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 30688
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.
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: Wed Dec 11 01:32:39 GMT 2019

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

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

Back to the top