[vala/staging] vala: Check for matching ownership of type-arguments
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging] vala: Check for matching ownership of type-arguments
- Date: Sun, 8 Apr 2018 17:20:17 +0000 (UTC)
commit 514fb744fb82828c9a5bd71ff80b7e41e3cfc34a
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Thu Apr 5 08:22:25 2018 +0200
vala: Check for matching ownership of type-arguments
Although don't complain (yet) if the target type is unowned.
https://bugzilla.gnome.org/show_bug.cgi?id=794979
tests/Makefile.am | 1 +
tests/generics/bug794979.test | 11 +++++++++++
vala/valadatatype.vala | 16 +++++++++++++++-
3 files changed, 27 insertions(+), 1 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 0645f2f..0d3544a 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -360,6 +360,7 @@ TESTS = \
generics/bug694765-1.vala \
generics/bug694765-2.vala \
generics/bug694765-3.vala \
+ generics/bug794979.test \
dbus/basic-types.test \
dbus/arrays.test \
dbus/structs.test \
diff --git a/tests/generics/bug794979.test b/tests/generics/bug794979.test
new file mode 100644
index 0000000..a4dd9cb
--- /dev/null
+++ b/tests/generics/bug794979.test
@@ -0,0 +1,11 @@
+Invalid Code
+
+class Foo<T> {
+}
+
+Foo<string> foo () {
+ return new Foo<unowned string> ();
+}
+
+void main () {
+}
diff --git a/vala/valadatatype.vala b/vala/valadatatype.vala
index 1bbbc82..208ffea 100644
--- a/vala/valadatatype.vala
+++ b/vala/valadatatype.vala
@@ -305,11 +305,25 @@ public abstract class Vala.DataType : CodeNode {
return true;
}
+ // check for matching ownership of type-arguments
+ var type_args = get_type_arguments ();
+ var target_type_args = target_type.get_type_arguments ();
+ if (type_args.size == target_type_args.size) {
+ for (int i = 0; i < type_args.size; i++) {
+ // FIXME let it pass if the target "container" is unowned, but should there
be a warning?
+ // Ignore non-boxed simple-type structs
+ if (!type_args[i].is_real_non_null_struct_type ()
+ && target_type.value_owned
+ && type_args[i].value_owned != target_type_args[i].value_owned) {
+ return false;
+ }
+ }
+ }
+
if (data_type != null && target_type.data_type != null && data_type.is_subtype_of
(target_type.data_type)) {
var base_type = SemanticAnalyzer.get_instance_base_type_for_member(this,
target_type.data_type, this);
// check compatibility of generic type arguments
var base_type_args = base_type.get_type_arguments();
- var target_type_args = target_type.get_type_arguments();
if (base_type_args.size == target_type_args.size) {
for (int i = 0; i < base_type_args.size; i++) {
// mutable generic types require type argument equality,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]