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 562017 - Vala is not properly calling methods from base structs
Vala is not properly calling methods from base structs
Status: RESOLVED NOTABUG
Product: vala
Classification: Core
Component: Structs
0.5.x
Other All
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2008-11-23 15:57 UTC by Sandino Flores-Moreno
Modified: 2010-01-13 05:26 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
make fields in structs inheritable (3.76 KB, patch)
2009-01-14 22:52 UTC, Andreas Brauchli
none Details | Review
a testcase to the patch (468 bytes, text/plain)
2009-01-14 22:53 UTC, Andreas Brauchli
  Details
The compiled result of given testcase (3.10 KB, text/plain)
2009-01-14 22:54 UTC, Andreas Brauchli
  Details
uses get_fields () on the struct instead of searching the scope (2.09 KB, patch)
2009-01-15 12:11 UTC, Andreas Brauchli
reviewed Details | Review
also set the correct parent_struct fields when using initializer fields (1.55 KB, patch)
2009-01-16 15:25 UTC, Andreas Brauchli
reviewed Details | Review

Description Sandino Flores-Moreno 2008-11-23 15:57:55 UTC
// From this program
public struct A {
	public void foo() { }
	public int dummy;
}

public struct B : A {
	public void moo() {
		base.foo(); // <-- Problematic line
	}
}

void main() {
	var b = B();
	b.moo();
}

/*
The line base.foo() is expanded to:
     a_foo ((_tmp0 = A (self), &_tmp0));

But that does not compile.
    test.c: In function ‘b_moo’:
    test.c:18: error: expected expression before ‘A’
    test.c: In function ‘_main’:

The line should be expanded to something like:
    a_foo ((A*) (self));
*/
Comment 1 Andreas Brauchli 2009-01-14 22:52:39 UTC
Created attachment 126469 [details] [review]
make fields in structs inheritable

This patch provides vala with inheritable fields in structs and typecasts the structs address when calling methods of an inherited struct.
Comment 2 Andreas Brauchli 2009-01-14 22:53:32 UTC
Created attachment 126470 [details]
a testcase to the patch
Comment 3 Andreas Brauchli 2009-01-14 22:54:33 UTC
Created attachment 126471 [details]
The compiled result of given testcase
Comment 4 Andreas Brauchli 2009-01-15 12:11:03 UTC
Created attachment 126499 [details] [review]
uses get_fields () on the struct instead of searching the scope

greatly simplifies the code by using get_fields () instead of searching the structs' scope, this also makes sure that the searched symbol is a field (which wasn't checked with the scope lookup)
the new property "Struct Struct.base_struct" does depend on 567661 which introduced the "DataType Struct.base_type" property
-- the compiled code of the testcase remains unchanged
Comment 5 Andreas Brauchli 2009-01-16 15:25:35 UTC
Created attachment 126586 [details] [review]
also set the correct parent_struct fields when using initializer fields

depends on attachment 126499 [details] [review]

this also fixes the case when initializing fields which where inherited.
var st = St () { my_i = 1, base_a = 3 };
Comment 6 Jürg Billeter 2009-01-16 18:19:12 UTC
Thanks for the patches. As mentioned on IRC, I'm not sure whether we actually want to support this. With structs there is no difference between the dynamic and the static type of a variable - in contrast to classes and interfaces.

I'm tending towards only supporting struct aliases. This would mean that structs with a base type are not allowed to have fields, and the compiler would generate just a typedef instead of a struct declaration for the subtype. In Sandino's example, this would be

typedef A B;
Comment 7 Sandino Flores-Moreno 2010-01-13 05:26:05 UTC
Marking as resolved just to close the cycle, since Jürg exposed good reasons
to consider this not a real issue.