GNOME Bugzilla – Bug 608250
Vala should use intermediate variables to initialize static structs
Last modified: 2010-02-03 19:06:03 UTC
Consider this test case: [test.vala] class TestParser: Object { static MarkupParser parser = {start, end, text, null, null}; void start (MarkupParseContext context, string name, string[] attr_names, string[] attr_values) throws MarkupError { } void end (MarkupParseContext context, string name) throws MarkupError { } void text (MarkupParseContext context, string text, size_t text_len) throws MarkupError { } } [/test.vala] For the class init, vala is currently generating: [class_init] static void test_parser_class_init (TestParserClass * klass) { ... test_parser_parser = { _test_parser_start_gmarkup_parser_start_element_func, _test_parser_end_gmarkup_parser_end_element_func, _test_parser_text_gmarkup_parser_text_func, NULL, NULL }; } [/class_init] Which does not compile: test.c: In function ‘test_parser_class_init’: test.c:104: error: expected expression before ‘{’ token Instead, vala should generate: [class_init] static void test_parser_class_init (TestParserClass * klass) { ... GMarkupParser tmp0 = { _test_parser_start_gmarkup_parser_start_element_func, _test_parser_end_gmarkup_parser_end_element_func, _test_parser_text_gmarkup_parser_text_func, NULL, NULL }; test_parser_parser = tmp0; } [/class_init] Which compiles fine. Actually, vala does exactly that to initialize instance variables. So, the same logic should apply to static variables too. And that explains why: http://live.gnome.org/Vala/MarkupSample Compiles with: const MarkupParser parser But not with: static MarkupParser parser
Created attachment 152458 [details] [review] Use intermediate variables to initialize static structs Fixes bug 608250.
I verified with current git, and it works fine. Could you commit it please?
commit 0958339872e8510a34f85edbc5a60ee21d46d840 Author: Marc-André Lureau <marcandre.lureau@gmail.com> Date: Thu Jan 28 01:01:04 2010 +0100 Use intermediate variables to initialize static structs Fixes bug 608250.