[vala/0.54] codegen: Detect usage of static type-parameter in runtime context
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/0.54] codegen: Detect usage of static type-parameter in runtime context
- Date: Wed, 10 Aug 2022 15:53:16 +0000 (UTC)
commit ce740060afe93e32b46f65481f8b49561b03c127
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Tue May 31 10:19:46 2022 +0200
codegen: Detect usage of static type-parameter in runtime context
Compact classes doesn't carry runtime information of its type-parameters.
In case this information is required we need report an error.
Fixes https://gitlab.gnome.org/GNOME/vala/issues/1326
codegen/valaccodebasemodule.vala | 5 +++++
tests/Makefile.am | 1 +
tests/generics/type-parameter-static-in-runtime.test | 14 ++++++++++++++
3 files changed, 20 insertions(+)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index c2d0fce0d..4082f502c 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -3044,6 +3044,11 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
public CCodeExpression get_type_id_expression (DataType type, bool is_chainup = false) {
if (type is GenericType) {
var type_parameter = ((GenericType) type).type_parameter;
+ unowned Symbol? parent = type_parameter.owner.owner;
+ if (parent is Class && ((Class) parent).is_compact) {
+ Report.error (type.source_reference, "static type-parameter `%s' can not be
used in runtime context", type_parameter.get_full_name ());
+ return new CCodeInvalidExpression();
+ }
string identifier = get_ccode_type_id (type_parameter);
return get_generic_type_expression (identifier, (GenericType) type, is_chainup);
} else {
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 3cf1c91f4..32d2c5641 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -764,6 +764,7 @@ TESTS = \
generics/string-literal-comparison.vala \
generics/type-parameter-properties.vala \
generics/type-parameter-property-clash.vala \
+ generics/type-parameter-static-in-runtime.test \
generics/value-pointer-type-access.vala \
generics/bug640330.vala \
generics/bug640330-2.test \
diff --git a/tests/generics/type-parameter-static-in-runtime.test
b/tests/generics/type-parameter-static-in-runtime.test
new file mode 100644
index 000000000..f6b6317fe
--- /dev/null
+++ b/tests/generics/type-parameter-static-in-runtime.test
@@ -0,0 +1,14 @@
+Invalid Code
+
+[Compact]
+class Foo<T> {
+ public Bar<T> bar () {
+ return new Bar<T> ();
+ }
+}
+
+class Bar<T> {
+}
+
+void main () {
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]