[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: Thu, 5 Apr 2018 06:47:54 +0000 (UTC)
commit fb5c94000b0c1558187f17ddea0d3bdfa3feb498
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Thu Apr 5 08:22:25 2018 +0200
vala: Check for matching ownership of type-arguments
https://bugzilla.gnome.org/show_bug.cgi?id=794979
tests/Makefile.am | 1 +
tests/generics/bug794979.test | 11 +++++++++++
vala/valadatatype.vala | 12 +++++++++++-
3 files changed, 23 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..5587b45 100644
--- a/vala/valadatatype.vala
+++ b/vala/valadatatype.vala
@@ -305,11 +305,21 @@ 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++) {
+ if (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]