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 734295 - struct inheritance between multiple files does not compile in C.
struct inheritance between multiple files does not compile in C.
Status: RESOLVED OBSOLETE
Product: vala
Classification: Core
Component: Structs
unspecified
Other All
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2014-08-05 14:42 UTC by Lim Jongrok
Modified: 2018-05-22 15:14 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Attached vala source (47 bytes, application/octet-stream)
2014-08-05 14:42 UTC, Lim Jongrok
  Details
Attached vala source (35 bytes, application/octet-stream)
2014-08-05 14:43 UTC, Lim Jongrok
  Details
Attached vala source (89 bytes, application/octet-stream)
2014-08-05 14:43 UTC, Lim Jongrok
  Details
Attached generated C source (1014 bytes, application/octet-stream)
2014-08-05 14:44 UTC, Lim Jongrok
  Details
Attached generated C source (969 bytes, application/octet-stream)
2014-08-05 14:44 UTC, Lim Jongrok
  Details
Attached generated C source (730 bytes, application/octet-stream)
2014-08-05 14:44 UTC, Lim Jongrok
  Details
Bug fix for 734295 (506 bytes, patch)
2015-10-26 15:30 UTC, Kristján
reviewed Details | Review
Enable inheritance of structs across files (2.43 KB, patch)
2015-10-27 18:38 UTC, Al Thomas
none Details | Review
Enable inheritance of structs across files (2.25 KB, patch)
2015-10-27 18:54 UTC, Al Thomas
none Details | Review

Description Lim Jongrok 2014-08-05 14:42:20 UTC
When a struct inherits from other struct in other file, it does compile at vala level (generation of C Code), but it does not compile at C level with a "Unknown Type" error.

This can be reproduced with any struct inheritance, which one of more of struct definitions are separated in other file(s), and here is one of example. which has two struct in each file.

astruct.vala: (also attached)

public struct AStruct {
	public int a_field;
}


bstruct.vala: (also attached)

public struct BStruct: AStruct {
}


bar.vala: (also attached)

public static int main (string[] args) {
	BStruct bstruct = new BStruct ();
	return 0;
}


[wsid@WSIDPC ~]$ valac --version
Vala 0.25.1



[wsid@WSIDPC ~]$ valac astruct.vala bstruct.vala bar.vala
bar.vala:2.20-2.33: warning: deprecated syntax, don't use `new' to initialize structs
	BStruct bstruct = new BStruct ();
	                  ^^^^^^^^^^^^^^
bar.vala:2.10-2.33: warning: local variable `bstruct' declared but never used
	BStruct bstruct = new BStruct ();
	        ^^^^^^^^^^^^^^^^^^^^^^^^
/home/wsid/bstruct.vala.c:11:9: error: unknown type name ‘AStruct’
 typedef AStruct BStruct;
         ^
/home/wsid/bar.vala.c:12:9: error: unknown type name ‘AStruct’
 typedef AStruct BStruct;
         ^
error: cc exited with status 256
Compilation failed: 1 error(s), 2 warning(s)



[wsid@WSIDPC ~]$ valac astruct.vala bstruct.vala bar.vala -C
bar.vala:2.20-2.33: warning: deprecated syntax, don't use `new' to initialize structs
	BStruct bstruct = new BStruct ();
	                  ^^^^^^^^^^^^^^
bar.vala:2.10-2.33: warning: local variable `bstruct' declared but never used
	BStruct bstruct = new BStruct ();
	        ^^^^^^^^^^^^^^^^^^^^^^^^
Compilation succeeded - 2 warning(s)



The generated C files are attached, and bstruct.c and bar.c lacks of definition of AStruct.
Comment 1 Lim Jongrok 2014-08-05 14:42:57 UTC
Created attachment 282575 [details]
Attached vala source
Comment 2 Lim Jongrok 2014-08-05 14:43:22 UTC
Created attachment 282577 [details]
Attached vala source
Comment 3 Lim Jongrok 2014-08-05 14:43:43 UTC
Created attachment 282578 [details]
Attached vala source
Comment 4 Lim Jongrok 2014-08-05 14:44:07 UTC
Created attachment 282579 [details]
Attached generated C source
Comment 5 Lim Jongrok 2014-08-05 14:44:31 UTC
Created attachment 282580 [details]
Attached generated C source
Comment 6 Lim Jongrok 2014-08-05 14:44:59 UTC
Created attachment 282581 [details]
Attached generated C source
Comment 7 Kristján 2015-10-26 15:30:21 UTC
Created attachment 314139 [details] [review]
Bug fix for 734295

Added a check to see whether the non-simple struct has a base struct, and if so, explicitly call for the base struct's declaration.
Comment 8 Al Thomas 2015-10-27 17:30:20 UTC
Review of attachment 314139 [details] [review]:

Cosmetically:
 - patch follows Vala project coding style
 - git apply produces 'trailing whitespace' message
 - git am cannot detect format of patch - better to use git format-patch when creating patch?

Functionally:
 - the code allows compilation by the C compiler, the C compiler no longer fails with "error: unknown type name ‘inherited_struct_name_in_other_file’"
 - this is tested on the example attached to the bug report and the example at https://github.com/GNOME/vala/pull/4

Elegance of solution:
 - there appears to be duplicate code
 - it looks as though the solution is to call generate_struct_declaration() whenever st.base_struct is not null, at present
   the code only does this when st is boolean, integer or float. so it would be better to move generate_struct_declaration()
   call out from and place it before the type check

There has been no regression testing for this review
Comment 9 Al Thomas 2015-10-27 18:38:04 UTC
Created attachment 314252 [details] [review]
Enable inheritance of structs across files

This uses Kristján's solution, but re-factors the type decision for boolean, integer and floating type structs to improve readability.

It makes it more explicit that Kristján's solution is to always call generate_struct_declaration() if there is a base_struct. Not sure if there are any side effects to this. What was happening before when the base struct was declared in the same file? 'make check' doesn't produce any errors.
Comment 10 Al Thomas 2015-10-27 18:54:20 UTC
Created attachment 314253 [details] [review]
Enable inheritance of structs across files

Correct whitespace error
Comment 11 GNOME Infrastructure Team 2018-05-22 15:14:36 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/464.