diff options
author | Rico Tzschichholz <ricotz@ubuntu.com> | 2020-01-24 22:48:06 +0100 |
---|---|---|
committer | Rico Tzschichholz <ricotz@ubuntu.com> | 2020-01-25 18:52:59 +0100 |
commit | 1d1733f907bff52f67435a563e2d9fbcc3de3f8d (patch) | |
tree | b6238429cecc845f5caad8b21c281d2d080839c7 /tests/chainup | |
parent | 83acacae8a6afc59093714ba8b3454abc87b7d45 (diff) | |
download | vala-1d1733f907bff52f67435a563e2d9fbcc3de3f8d.tar.gz |
codegen: Handle different type-symbols in visit_base_access()
It is required to distinguish between classes, compact classes, structs
and simple-type structs.
Fixes https://gitlab.gnome.org/GNOME/vala/issues/901
Diffstat (limited to 'tests/chainup')
-rw-r--r-- | tests/chainup/class-compact-base.vala | 37 | ||||
-rw-r--r-- | tests/chainup/struct-no-gtype-base.vala | 27 | ||||
-rw-r--r-- | tests/chainup/struct-simple-no-gtype-base.vala | 25 |
3 files changed, 89 insertions, 0 deletions
diff --git a/tests/chainup/class-compact-base.vala b/tests/chainup/class-compact-base.vala new file mode 100644 index 000000000..1359c3be7 --- /dev/null +++ b/tests/chainup/class-compact-base.vala @@ -0,0 +1,37 @@ +[Compact] +public class Foo { + public int a; + public int b; + + public Foo () { + a = 23; + } + + public int sum () { + return this.a + this.b; + } +} + +public class Bar : Foo { + public Bar () { + base (); + this.b = 42; + } + + public int mul () { + return this.a * this.b; + } + + public int mul2 () { + return base.a * base.b; + } +} + +void main () { + var bar = new Bar (); + assert (bar.a == 23); + assert (bar.b == 42); + assert (bar.sum () == 65); + assert (bar.mul () == 966); + assert (bar.mul2 () == 966); +} diff --git a/tests/chainup/struct-no-gtype-base.vala b/tests/chainup/struct-no-gtype-base.vala new file mode 100644 index 000000000..c0e39b894 --- /dev/null +++ b/tests/chainup/struct-no-gtype-base.vala @@ -0,0 +1,27 @@ +[CCode (has_type_id = false)] +struct Foo { + public int a; + public int b; + + public int sum () { + return this.a + this.b; + } +} + +[CCode (has_type_id = false)] +struct Bar : Foo { + public int mul () { + return this.a * this.b; + } + + public int mul2 () { + return base.a * base.b; + } +} + +void main () { + Bar bar = { 23, 42 }; + assert (bar.sum () == 65); + assert (bar.mul () == 966); + assert (bar.mul2 () == 966); +} diff --git a/tests/chainup/struct-simple-no-gtype-base.vala b/tests/chainup/struct-simple-no-gtype-base.vala new file mode 100644 index 000000000..ee19bc223 --- /dev/null +++ b/tests/chainup/struct-simple-no-gtype-base.vala @@ -0,0 +1,25 @@ +[IntegerType (rank = 6, signed = true, width = 32)] +[SimpleType] +[CCode (has_type_id = false)] +struct foo_t { + public int sum (foo_t b) { + return this + b; + } +} + +[CCode (has_type_id = false)] +struct bar_t : foo_t { + public int mul (bar_t b) { + return this * b; + } + public int mul2 (bar_t b) { + return base * b; + } +} + +void main () { + bar_t bar = 23; + assert (bar.sum (42) == 65); + assert (bar.mul (42) == 966); + assert (bar.mul2 (42) == 966); +} |