]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Don't require constant initializer in fast-vapi
authorRico Tzschichholz <ricotz@ubuntu.com>
Thu, 14 Nov 2019 20:04:42 +0000 (21:04 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Fri, 15 Nov 2019 07:25:33 +0000 (08:25 +0100)
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
tests/fastvapi/Makefile.am
tests/fastvapi/fastvapitest.vala
tests/fastvapi/fastvapitest.vapi-expected
tests/fastvapi/usefastvapitest.vala [new file with mode: 0644]
vala/valaconstant.vala

index ba3ab2d9c7042dcf23701efce0402ca586de82a4..d08b1918f221cd9d368e44951bac72a2819f2312 100644 (file)
@@ -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);
index b960ac4b146d89e46f9513b6855f22c52f60111c..cc002565434853732f1bd90d528915325cd6fead 100644 (file)
@@ -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)
index bfbd371c6f10d5d5ae901ec480ae3d6cee863199..37229660b9e341acff27876fb8d7aab7a4685bb6 100644 (file)
@@ -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,
+       }
 }
index 3a8ab23b59f41fa1705ce53b5d8ff8308cc5e15d..5530facc13745f3914061ad2adc5fae75a9154af 100644 (file)
@@ -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 (file)
index 0000000..46f9dda
--- /dev/null
@@ -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);
+}
index 519d43b1bc5be2f1c9cea5359bdbafad97d43009..3ff4bf3c4f994018498672051c91c2a8d8c8c2be 100644 (file)
@@ -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;