Re: [Vala] Incorrect C code generated



Mate, this works:

struct DataStruct {
   int i;
 }
 class ClassA : Object {
   public DataStruct a { get; set; }
   public ClassA(DataStruct a) {
     this.a = a;
   }
 }
 class ClassB : Object {
   public Value b { get; set; }
   public ClassB(Value b) {
     this.b = b;
   }
 }
 class Main {
   static void main() {
     var a = new ClassA({ 1 });
     var b = new ClassB(a.a);
     b.notify["b"].connect((obj, prop) => {
             DataStruct data = (DataStruct)(b.b);
             a.a = data;
         });
   }
 }

Instead of `a.a = (N)b.b;`, I expanded to
```
             DataStruct data = (DataStruct)(b.b);
             a.a = data;
```

Splitting it to two lines made it work, I don't know why. The point
is, ` (DataStruct)(b.b)`
is not a simple cast, it does perform runtime checks to make sure that the
type to be cast is the type of the Value's contained object. This runtime
check is what got broken in a single liner.

Also, be careful with of single letter types, I got some errors due to 'N'
type not being found in runtime.


On Tue, Mar 22, 2016 at 5:41 PM Abderrahim Kitouni <a kitouni gmail com>
wrote:

Hi

Le mar 22 mars 2016 20:37, Dmitry Golovin <dima golovin in> a écrit :

Hello!

Discussed today on the IRC channel, also posting it to the mailing list.

I don't know if it is a vala bug or I am just using things incorrectly.

Here is my code:

    struct N {
      int i;
    }
    class ClassA : Object {
      public N a { get; set; }
      public ClassA(N a) {
        this.a = a;
      }
    }
    class ClassB : Object {
      public Value b { get; set; }
      public ClassB(Value b) {
        this.b = b;
      }
    }
    class Main {
      static void main() {
        var a = new ClassA({ 1 });
        var b = new ClassB(a.a);
        b.notify["b"].connect((obj, prop) => { a.a = (N)b.b; });


A random idea: try casting to (N?) instead.

HTH
_______________________________________________
vala-list mailing list
vala-list gnome org
https://mail.gnome.org/mailman/listinfo/vala-list



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]