After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 546440 - Vala interface fields do not generate correct code
Vala interface fields do not generate correct code
Status: RESOLVED OBSOLETE
Product: vala
Classification: Core
Component: Objects
unspecified
Other All
: Normal enhancement
: 1.2
Assigned To: Vala maintainers
Vala maintainers
: 583598 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2008-08-05 17:06 UTC by Emmanuele Bassi (:ebassi)
Modified: 2018-05-22 13:09 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
[TEST] Interface field test case (873 bytes, text/plain)
2008-08-05 17:07 UTC, Emmanuele Bassi (:ebassi)
  Details
result of the interfaces.vala compilation (8.17 KB, text/plain)
2008-08-05 17:12 UTC, Emmanuele Bassi (:ebassi)
  Details
codegen: Initial support for class fields in interfaces (6.39 KB, patch)
2011-09-22 23:15 UTC, Luca Bruno
none Details | Review

Description Emmanuele Bassi (:ebassi) 2008-08-05 17:06:08 UTC
I'm attaching an updated version of the interfaces.vala test case which adds an interface public field and then changes its value inside the class constructor:

  public abstract class Ibaz : Object {
    public class int public_field;
  }

  public class Baz : Object, Ibaz {
    class construct {
      public_field = 42;
    }
  }

will print out a warning:

./testrunner.sh: line 42: 24833 Trace/breakpoint trap   $VALAC -C --vapidir "$vapidir" --pkg gee-1.0 --basedir $topsrcdir -d $topbuilddir $testsrc.vala > $testbuild.err 2>&1
ERROR: Compiling ./interfaces.vala

GLib-GObject-WARNING **: invalid cast from `ValaInterface' to `ValaClass'
aborting...

the resulting code does not cast the interface correctly inside the base_init().
Comment 1 Emmanuele Bassi (:ebassi) 2008-08-05 17:07:15 UTC
Created attachment 115917 [details]
[TEST] Interface field test case

test case showing the interface public field error in the compiler.
Comment 2 Emmanuele Bassi (:ebassi) 2008-08-05 17:12:10 UTC
Created attachment 115919 [details]
result of the interfaces.vala compilation
Comment 3 Emmanuele Bassi (:ebassi) 2008-08-05 17:31:26 UTC
it occurs to me that I might be completely off course, here.

in short: if I can set class fields using the class constructor, how do I set interface fields? from IRC:

< juergbi> ebassi: interface fields are not supported at all, yet, only class fields
< juergbi> although they should be pretty similar to implement

what I think should be needed is a way to override the interface_init function from Vala, like:

  public Ibaz () {
    public_field = 42;
  }

which would be translated into:

  static void ibaz_iface_init (IbazIface *iface)
  {
    iface->public_field = 42;
    /* vtable fields are added here */
  }

or a:

  Ibaz constructor {
  }

which would allow overriding the interface_init for multiple types.
Comment 4 Jürg Billeter 2008-12-15 23:53:52 UTC
Interface fields have not been implemented yet at all. We should be able to support them int he same way as class fields, though.
Comment 5 Michael 'Mickey' Lauer 2009-10-08 11:51:53 UTC
Meanwhile, valac emits the following error for your testcase:

iface.vala:8.9-8.37: error: class fields are not supported in compact classes
        public class int public_field;
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

The actual case remains open though.
Comment 6 Luca Bruno 2011-08-08 20:42:24 UTC
*** Bug 583598 has been marked as a duplicate of this bug. ***
Comment 7 Luca Bruno 2011-09-22 23:15:36 UTC
Created attachment 197303 [details] [review]
codegen: Initial support for class fields in interfaces

Define the field in the struct and allow accessing the field from an
instance context.

Partially fixes bug 546440.

What's next:
1) Private fields
2) Syntax for interface constructor (I like the proposed IBaz construct {})
or something like that
3) Access the field in static/class context
Comment 8 Daniel Espinosa 2017-02-17 18:10:42 UTC
Vala as pointed out, have no support for all cases in C generated code. This a little special case, should be worked as enhancement, as pointed before.

This feature is not blocked for a 1.0 release, because current solution cover mayor cases.
Comment 9 GNOME Infrastructure Team 2018-05-22 13:09:06 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to GNOME's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/vala/issues/12.