Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
vala
vala
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 701
    • Issues 701
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
  • Merge Requests 39
    • Merge Requests 39
  • Operations
    • Operations
    • Incidents
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Analytics
    • Analytics
    • Repository
    • Value Stream
  • External Wiki
    • External Wiki
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
  • GNOME
  • valavala
  • Issues
  • #899

Closed
Open
Opened Jan 21, 2020 by Marvin W@larma

Compiler warning when initializing property with constructor of implementation of interface with abstract property

The following code snippet causes a compiler warning:

interface Test {
  public abstract string test { get; set; }
}

class TestImpl : Test {
  public string test { get; set; }
}

void main() {
  new TestImpl() { test = "Test" };
}
early_init.vala.c:376:17: warning: passing argument 1 of ‘test_set_test’ from incompatible pointer type [-Wincompatible-pointer-types]
  376 |  test_set_test (_tmp1_, _tmp0_);
      |                 ^~~~~~
      |                 |
      |                 TestImpl * {aka struct _TestImpl *}
early_init.vala.c:92:22: note: expected ‘Test *’ {aka ‘struct _Test *’} but argument is of type ‘TestImpl *’ {aka ‘struct _TestImpl *’}
   92 | test_set_test (Test* self,

This is because the function is compiled to:

void
_vala_main (void)
{
        gchar* _tmp0_;
        TestImpl* _tmp1_ = NULL;
        TestImpl* _tmp2_;
        _tmp0_ = g_strdup ("Test");
        _tmp1_ = test_impl_new ();
        test_set_test (_tmp1_, _tmp0_);
        _g_free0 (_tmp0_);
        _tmp2_ = _tmp1_;
        _test_impl_unref0 (_tmp2_);
}

When changing main to

void main() {
  var test = new TestImpl();
  test.test = "Test";
}

the code is compiled to

void
_vala_main (void)
{
        TestImpl* test = NULL;
        TestImpl* _tmp0_;
        _tmp0_ = test_impl_new ();
        test = _tmp0_;
        test_set_test ((Test*) test, "Test");
        _test_impl_unref0 (test);
}

instead, which doesn't impose any warning (and also looks way cleaner in C, but less nice in Vala).

To upload designs, you'll need to enable LFS and have admin enable hashed storage. More information
Assignee
Assign to
0.48
Milestone
0.48
Assign milestone
Time tracking
None
Due date
None
Reference: GNOME/vala#899