anuragraghavan / franca

Automatically exported from code.google.com/p/franca
0 stars 0 forks source link

Add type cast operator #94

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
We observed that to posibility to assign a struct to a variable with a type on 
a higher level in the inheritance hierarchie might be confusing. For example, 
if we have the following definitions:

struct S1 {
  Boolean aBool
}
struct S2 extends S1 {
  Integer anInt
}

const S2 c {
  aBool: false, anInt:1
}

Now think of the initialization of an other constant by use of c:

const S1 c_ = c

This is quite fine, if you have in mind that the elements of c_ get initialized 
by use of only those elements of c inherited from S1 (aBool). But what about 
the other elements (anInt)? It is NOT part of c_ and gets lost.

To keep this capability of assignments along the inheritance hierarchy, but to 
make it clear what happens, we decided to introduce an explicit casting. In the 
example above the initialization will look like the following:

const S1 c_ = (S1) c

Original issue reported on code.google.com by SteffenW...@gmail.com on 28 Mar 2014 at 12:53

GoogleCodeExporter commented 9 years ago

Original comment by SteffenW...@gmail.com on 28 Mar 2014 at 12:54

GoogleCodeExporter commented 9 years ago
Type casts have been implemented using slightly different syntax:
const S1 c_ = <S1> c

Original comment by SteffenW...@gmail.com on 13 Jun 2014 at 12:25