From 5bf84028dba1e3f9d4be590b0646afeb9dfa3d7f Mon Sep 17 00:00:00 2001 From: Rico Tzschichholz Date: Thu, 14 Nov 2019 21:04:42 +0100 Subject: [PATCH] vala: Don't require constant initializer in fast-vapi Regression of 984c034256de3830d6daa0ab6f5eff108dea09bb Extend --fast-vapi test by using --use-fast-vapi See https://github.com/dino/dino/issues/646 and https://gitlab.gnome.org/GNOME/vala/issues/461 --- codegen/valaccodebasemodule.vala | 2 +- tests/fastvapi/Makefile.am | 10 +++++++++- tests/fastvapi/fastvapitest.vala | 7 +++++++ tests/fastvapi/fastvapitest.vapi-expected | 9 +++++++++ tests/fastvapi/usefastvapitest.vala | 7 +++++++ vala/valaconstant.vala | 7 +++++-- 6 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 tests/fastvapi/usefastvapitest.vala diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala index ba3ab2d9c..d08b1918f 100644 --- a/codegen/valaccodebasemodule.vala +++ b/codegen/valaccodebasemodule.vala @@ -971,7 +971,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { return; } - if (!c.external) { + if (!c.external || (c.source_type == SourceFileType.FAST && c.value != null)) { generate_type_declaration (c.type_reference, decl_space); c.value.emit (this); diff --git a/tests/fastvapi/Makefile.am b/tests/fastvapi/Makefile.am index b960ac4b1..cc0025654 100644 --- a/tests/fastvapi/Makefile.am +++ b/tests/fastvapi/Makefile.am @@ -8,16 +8,24 @@ check-fastvapi: $(top_builddir)/compiler/valac --basedir $(srcdir) \ $(srcdir)/fastvapitest.vala; \ tail -n +3 fastvapitest.vapi | diff -wu $(srcdir)/fastvapitest.vapi-expected - || exit 1; \ - rm -f fastvapitest.vapi fastvapitest.c + G_DEBUG=fatal-warnings $(top_builddir)/compiler/valac \ + -C \ + --disable-version-header \ + --use-fast-vapi fastvapitest.vapi \ + --basedir $(srcdir) \ + $(srcdir)/usefastvapitest.vala; \ + rm -f fastvapitest.vapi fastvapitest.c usefastvapitest.c check: check-fastvapi EXTRA_DIST = \ fastvapitest.vala \ fastvapitest.vapi-expected \ + usefastvapitest.vala \ $(NULL) CLEANFILES = \ fastvapitest.c \ fastvapitest.vapi \ + usefastvapitest.c \ $(NULL) diff --git a/tests/fastvapi/fastvapitest.vala b/tests/fastvapi/fastvapitest.vala index bfbd371c6..37229660b 100644 --- a/tests/fastvapi/fastvapitest.vala +++ b/tests/fastvapi/fastvapitest.vala @@ -41,4 +41,11 @@ namespace FastVapi { public struct TestSubStruct : TestStruct { public static int static_field_name; } + + public const int CONSTANT_TWO = CONSTANT; + + public enum EnumTestTwo { + VALUE = 3, + VALUE_TWO = VALUE, + } } diff --git a/tests/fastvapi/fastvapitest.vapi-expected b/tests/fastvapi/fastvapitest.vapi-expected index 3a8ab23b5..5530facc1 100644 --- a/tests/fastvapi/fastvapitest.vapi-expected +++ b/tests/fastvapi/fastvapitest.vapi-expected @@ -41,6 +41,13 @@ namespace FastVapi { [Source (filename = "fastvapitest.vala", line = 5, column = 3)] VALUE } + [Source (filename = "fastvapitest.vala", line = 47, column = 2)] + public enum EnumTestTwo { + [Source (filename = "fastvapitest.vala", line = 48, column = 3)] + VALUE = 3, + [Source (filename = "fastvapitest.vala", line = 49, column = 3)] + VALUE_TWO + } [Source (filename = "fastvapitest.vala", line = 8, column = 2)] public errordomain ErrorTest { [Source (filename = "fastvapitest.vala", line = 9, column = 3)] @@ -50,4 +57,6 @@ namespace FastVapi { public delegate bool DelegateTest (int param); [Source (filename = "fastvapitest.vala", line = 2, column = 2)] public const int CONSTANT = 42; + [Source (filename = "fastvapitest.vala", line = 45, column = 2)] + public const int CONSTANT_TWO; } diff --git a/tests/fastvapi/usefastvapitest.vala b/tests/fastvapi/usefastvapitest.vala new file mode 100644 index 000000000..46f9ddaa1 --- /dev/null +++ b/tests/fastvapi/usefastvapitest.vala @@ -0,0 +1,7 @@ +void main () { + assert (FastVapi.CONSTANT == 42); + assert (FastVapi.CONSTANT_TWO == 42); + + assert (FastVapi.EnumTestTwo.VALUE == 3); + assert (FastVapi.EnumTestTwo.VALUE_TWO == 3); +} diff --git a/vala/valaconstant.vala b/vala/valaconstant.vala index 519d43b1b..3ff4bf3c4 100644 --- a/vala/valaconstant.vala +++ b/vala/valaconstant.vala @@ -123,8 +123,11 @@ public class Vala.Constant : Symbol { if (!external) { if (value == null) { - error = true; - Report.error (source_reference, "A const field requires a value to be provided"); + // constants from fast-vapi files are special + if (source_type != SourceFileType.FAST) { + error = true; + Report.error (source_reference, "A const field requires a value to be provided"); + } } else { value.target_type = type_reference; -- 2.47.2