Skip to content

Commit

Permalink
vala: Don't require constant initializer in fast-vapi
Browse files Browse the repository at this point in the history
Regression of 984c034

Extend --fast-vapi test by using --use-fast-vapi

See dino/dino#646
and https://gitlab.gnome.org/GNOME/vala/issues/461
  • Loading branch information
ricotz committed Nov 15, 2019
1 parent 81948df commit 0244bd3
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 4 deletions.
2 changes: 1 addition & 1 deletion codegen/valaccodebasemodule.vala
Expand Up @@ -961,7 +961,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);
Expand Down
10 changes: 9 additions & 1 deletion tests/fastvapi/Makefile.am
Expand Up @@ -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)
7 changes: 7 additions & 0 deletions tests/fastvapi/fastvapitest.vala
Expand Up @@ -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,
}
}
9 changes: 9 additions & 0 deletions tests/fastvapi/fastvapitest.vapi-expected
Expand Up @@ -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)]
Expand All @@ -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;
}
7 changes: 7 additions & 0 deletions 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);
}
7 changes: 5 additions & 2 deletions vala/valaconstant.vala
Expand Up @@ -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;

Expand Down

0 comments on commit 0244bd3

Please sign in to comment.