[vala/staging] codegen: Add missing cast to access base-class members with class/static ctor
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging] codegen: Add missing cast to access base-class members with class/static ctor
- Date: Tue, 31 Aug 2021 14:35:53 +0000 (UTC)
commit 9fc4f4ee4f27314b6494147e880b2e76c5f3e9d0
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Tue Aug 31 16:28:05 2021 +0200
codegen: Add missing cast to access base-class members with class/static ctor
Regression of 9cbd53b8d79aa4c394ddf49e766f2c15fc476906
Fixes https://gitlab.gnome.org/GNOME/vala/issues/1221
codegen/valaccodebasemodule.vala | 8 +++++++-
tests/objects/fields.c-expected | 16 ++++++++++++++++
tests/objects/fields.vala | 20 ++++++++++++++++++++
3 files changed, 43 insertions(+), 1 deletion(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 54fc3e184..f7321b72a 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -2622,7 +2622,13 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
cast = call;
} else {
// Accessing the member from a static or class constructor
- cast = new CCodeIdentifier ("klass");
+ if (current_class == cl) {
+ cast = new CCodeIdentifier ("klass");
+ } else {
+ call = new CCodeFunctionCall (new CCodeIdentifier
(get_ccode_class_type_function (cl)));
+ call.add_argument (new CCodeIdentifier ("klass"));
+ cast = call;
+ }
}
return cast;
}
diff --git a/tests/objects/fields.c-expected b/tests/objects/fields.c-expected
index 6d7391968..03828580c 100644
--- a/tests/objects/fields.c-expected
+++ b/tests/objects/fields.c-expected
@@ -701,6 +701,10 @@ faz_base_init (FazClass * klass)
_vala_assert (FAZ_GET_CLASS_PRIVATE (klass)->private_class_field == 42, "private_class_field == 42");
FAZ_GET_CLASS_PRIVATE (klass)->private_class_field = 24;
_vala_assert (FAZ_GET_CLASS_PRIVATE (klass)->private_class_field == 24, "private_class_field == 24");
+ _vala_assert (FOO_CLASS (klass)->public_base_class_field == 42, "public_base_class_field == 42");
+ FOO_CLASS (klass)->public_base_class_field = 24;
+ _vala_assert (FOO_CLASS (klass)->public_base_class_field == 24, "public_base_class_field == 24");
+ FOO_CLASS (klass)->public_base_class_field = 42;
}
static void
@@ -722,6 +726,10 @@ faz_class_init (FazClass * klass,
_vala_assert (FAZ_GET_CLASS_PRIVATE (klass)->private_class_field == 42, "private_class_field == 42");
FAZ_GET_CLASS_PRIVATE (klass)->private_class_field = 24;
_vala_assert (FAZ_GET_CLASS_PRIVATE (klass)->private_class_field == 24, "private_class_field == 24");
+ _vala_assert (FOO_CLASS (klass)->public_base_class_field == 42, "public_base_class_field == 42");
+ FOO_CLASS (klass)->public_base_class_field = 24;
+ _vala_assert (FOO_CLASS (klass)->public_base_class_field == 24, "public_base_class_field == 24");
+ FOO_CLASS (klass)->public_base_class_field = 42;
}
static void
@@ -1000,6 +1008,10 @@ baz_base_init (BazClass * klass)
_vala_assert (BAZ_GET_CLASS_PRIVATE (klass)->private_class_field == 42, "private_class_field == 42");
BAZ_GET_CLASS_PRIVATE (klass)->private_class_field = 24;
_vala_assert (BAZ_GET_CLASS_PRIVATE (klass)->private_class_field == 24, "private_class_field == 24");
+ _vala_assert (BAR_CLASS (klass)->public_base_class_field == 42, "public_base_class_field == 42");
+ BAR_CLASS (klass)->public_base_class_field = 24;
+ _vala_assert (BAR_CLASS (klass)->public_base_class_field == 24, "public_base_class_field == 24");
+ BAR_CLASS (klass)->public_base_class_field = 42;
}
static void
@@ -1021,6 +1033,10 @@ baz_class_init (BazClass * klass,
_vala_assert (BAZ_GET_CLASS_PRIVATE (klass)->private_class_field == 42, "private_class_field == 42");
BAZ_GET_CLASS_PRIVATE (klass)->private_class_field = 24;
_vala_assert (BAZ_GET_CLASS_PRIVATE (klass)->private_class_field == 24, "private_class_field == 24");
+ _vala_assert (BAR_CLASS (klass)->public_base_class_field == 42, "public_base_class_field == 42");
+ BAR_CLASS (klass)->public_base_class_field = 24;
+ _vala_assert (BAR_CLASS (klass)->public_base_class_field == 24, "public_base_class_field == 24");
+ BAR_CLASS (klass)->public_base_class_field = 42;
}
static void
diff --git a/tests/objects/fields.vala b/tests/objects/fields.vala
index 0872045bb..e14572bd9 100644
--- a/tests/objects/fields.vala
+++ b/tests/objects/fields.vala
@@ -32,6 +32,11 @@ class Faz : Foo {
assert (private_class_field == 42);
private_class_field = 24;
assert (private_class_field == 24);
+
+ assert (public_base_class_field == 42);
+ public_base_class_field = 24;
+ assert (public_base_class_field == 24);
+ public_base_class_field = 42;
}
static construct {
@@ -42,6 +47,11 @@ class Faz : Foo {
assert (private_class_field == 42);
private_class_field = 24;
assert (private_class_field == 24);
+
+ assert (public_base_class_field == 42);
+ public_base_class_field = 24;
+ assert (public_base_class_field == 24);
+ public_base_class_field = 42;
}
public void action () {
@@ -132,6 +142,11 @@ class Baz : Bar {
assert (private_class_field == 42);
private_class_field = 24;
assert (private_class_field == 24);
+
+ assert (public_base_class_field == 42);
+ public_base_class_field = 24;
+ assert (public_base_class_field == 24);
+ public_base_class_field = 42;
}
static construct {
@@ -142,6 +157,11 @@ class Baz : Bar {
assert (private_class_field == 42);
private_class_field = 24;
assert (private_class_field == 24);
+
+ assert (public_base_class_field == 42);
+ public_base_class_field = 24;
+ assert (public_base_class_field == 24);
+ public_base_class_field = 42;
}
public void action () {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]