diff options
author | Rico Tzschichholz <ricotz@ubuntu.com> | 2022-02-06 08:57:35 +0100 |
---|---|---|
committer | Rico Tzschichholz <ricotz@ubuntu.com> | 2022-02-09 22:26:14 +0100 |
commit | fbaafe69513a9d01e9300b0a6b22e6400b489b77 (patch) | |
tree | 82be52ca39346a91d62ed443cb421b7e3124da1d | |
parent | 9fe5e824a0366a6a51153b4b4f7fb1796b695f31 (diff) | |
download | vala-fbaafe69513a9d01e9300b0a6b22e6400b489b77.tar.gz |
vala: Move dynamic property errors to semantic analyzer pass
-rw-r--r-- | tests/Makefile.am | 2 | ||||
-rw-r--r-- | tests/objects/property-dynamic-not-supported.test | 10 | ||||
-rw-r--r-- | tests/objects/property-dynamic-type-inference.vala | 25 | ||||
-rw-r--r-- | vala/valamemberaccess.vala | 8 |
4 files changed, 45 insertions, 0 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index 02be6c44f..ce61d0115 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -512,6 +512,8 @@ TESTS = \ objects/property-array.vala \ objects/property-array-length.vala \ objects/property-base-access.vala \ + objects/property-dynamic-not-supported.test \ + objects/property-dynamic-type-inference.vala \ objects/property-enum.vala \ objects/property-notify.vala \ objects/property-notify-owned-getter.vala \ diff --git a/tests/objects/property-dynamic-not-supported.test b/tests/objects/property-dynamic-not-supported.test new file mode 100644 index 000000000..15d659099 --- /dev/null +++ b/tests/objects/property-dynamic-not-supported.test @@ -0,0 +1,10 @@ +Invalid Code + +class Foo { +} + +void main () { + dynamic Foo foo = new Foo (); + foo.bar = "foo"; + int i = foo.bar; +} diff --git a/tests/objects/property-dynamic-type-inference.vala b/tests/objects/property-dynamic-type-inference.vala new file mode 100644 index 000000000..3f555da3c --- /dev/null +++ b/tests/objects/property-dynamic-type-inference.vala @@ -0,0 +1,25 @@ +class Foo : Object { + [CCode (cname = "manam")] + public Foo? bar { owned get; set; } +} + +void main () { + var foo = new Foo (); + assert (foo.ref_count == 1); + + dynamic Foo dfoo = foo; + assert (foo.ref_count == 2); + + assert (dfoo.manam == null); + assert (foo.ref_count == 2); + + dfoo.manam = foo; + assert (foo.ref_count == 3); + + foo = dfoo.manam; + assert (foo.ref_count == 3); + + dfoo = null; + foo.bar = null; + assert (foo.ref_count == 1); +} diff --git a/vala/valamemberaccess.vala b/vala/valamemberaccess.vala index ab671d026..d13e322b7 100644 --- a/vala/valamemberaccess.vala +++ b/vala/valamemberaccess.vala @@ -478,6 +478,10 @@ public class Vala.MemberAccess : Expression { prop.owner = inner.value_type.type_symbol.scope; dynamic_object_type.type_symbol.scope.add (null, prop); symbol_reference = prop; + if (!dynamic_object_type.type_symbol.is_subtype_of (context.analyzer.object_type)) { + Report.error (source_reference, "dynamic properties are not supported for `%s'", dynamic_object_type.type_symbol.get_full_name ()); + error = true; + } } } else if (parent_node is MemberAccess && inner is MemberAccess && parent_node.parent_node is MethodCall) { unowned MemberAccess ma = (MemberAccess) parent_node; @@ -520,6 +524,10 @@ public class Vala.MemberAccess : Expression { prop.owner = inner.value_type.type_symbol.scope; dynamic_object_type.type_symbol.scope.add (null, prop); symbol_reference = prop; + if (!dynamic_object_type.type_symbol.is_subtype_of (context.analyzer.object_type)) { + Report.error (source_reference, "dynamic properties are not supported for %s", dynamic_object_type.type_symbol.get_full_name ()); + error = true; + } } if (symbol_reference != null) { may_access_instance_members = true; |