diff options
author | Rico Tzschichholz <ricotz@ubuntu.com> | 2021-06-23 10:56:01 +0200 |
---|---|---|
committer | Rico Tzschichholz <ricotz@ubuntu.com> | 2021-06-23 13:08:31 +0200 |
commit | 700127449b3825ecb262e541a397ebdd065b45cd (patch) | |
tree | 823d1c08a116ce18c39de8b66b28b1e25360c46f /tests | |
parent | 75b0117dfbbedea75fd91e4ced8d24e499db4b07 (diff) | |
download | vala-700127449b3825ecb262e541a397ebdd065b45cd.tar.gz |
codegen: Fix variadic constructors for compact classes and structs
Fixes https://gitlab.gnome.org/GNOME/vala/issues/1195
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile.am | 4 | ||||
-rw-r--r-- | tests/objects/constructor-variadic-invalid.test (renamed from tests/objects/constructor-variadic.test) | 0 | ||||
-rw-r--r-- | tests/objects/constructor-variadic.vala | 35 | ||||
-rw-r--r-- | tests/structs/constructor-variadic.vala | 18 |
4 files changed, 56 insertions, 1 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index 5dfcd32a9..6f3064dad 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -343,6 +343,7 @@ TESTS = \ structs/struct-static-field-initializer.test \ structs/struct-static-property-initializer.test \ structs/structs.vala \ + structs/constructor-variadic.vala \ structs/constructor-wrong-name.test \ structs/default-gtype.vala \ structs/gmutex.vala \ @@ -442,7 +443,8 @@ TESTS = \ objects/compact-class-custom-ref.vala \ objects/constructor-abstract-public.test \ objects/constructor-inner-error.vala \ - objects/constructor-variadic.test \ + objects/constructor-variadic.vala \ + objects/constructor-variadic-invalid.test \ objects/constructor-wrong-name.test \ objects/constructors.vala \ objects/destructors.vala \ diff --git a/tests/objects/constructor-variadic.test b/tests/objects/constructor-variadic-invalid.test index ed9527d99..ed9527d99 100644 --- a/tests/objects/constructor-variadic.test +++ b/tests/objects/constructor-variadic-invalid.test diff --git a/tests/objects/constructor-variadic.vala b/tests/objects/constructor-variadic.vala new file mode 100644 index 000000000..58a97fe1f --- /dev/null +++ b/tests/objects/constructor-variadic.vala @@ -0,0 +1,35 @@ +class Foo { + public string s; + + public Foo (string first_arg, ...) { + assert (first_arg == "foo"); + va_list args = va_list (); + string second_arg = args.arg<string> (); + assert (second_arg == "bar"); + s = first_arg + second_arg; + } +} + +[Compact] +class Bar { + public string s; + + public Bar (string first_arg, ...) { + assert (first_arg == "bar"); + va_list args = va_list (); + string second_arg = args.arg<string> (); + assert (second_arg == "foo"); + s = first_arg + second_arg; + } +} + +void main () { + { + var foo = new Foo ("foo", "bar"); + assert (foo.s == "foobar"); + } + { + var bar = new Bar ("bar", "foo"); + assert (bar.s == "barfoo"); + } +} diff --git a/tests/structs/constructor-variadic.vala b/tests/structs/constructor-variadic.vala new file mode 100644 index 000000000..2602fe20b --- /dev/null +++ b/tests/structs/constructor-variadic.vala @@ -0,0 +1,18 @@ +struct Foo { + public string s; + + public Foo (string first_arg, ...) { + assert (first_arg == "foo"); + va_list args = va_list (); + string second_arg = args.arg<string> (); + assert (second_arg == "bar"); + s = first_arg + second_arg; + } +} + +void main () { + { + var foo = Foo ("foo", "bar"); + assert (foo.s == "foobar"); + } +} |