[vala/wip/issue/658: 43/48] No `dynamic` and `params` for anonymous delegates
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/issue/658: 43/48] No `dynamic` and `params` for anonymous delegates
- Date: Sat, 31 Oct 2020 15:08:17 +0000 (UTC)
commit 26ad822aa2717b0d26361d77120b6c6fca61d0c6
Author: Nick Schrader <nick schrader mailbox org>
Date: Thu Oct 29 12:37:08 2020 -0300
No `dynamic` and `params` for anonymous delegates
tests/Makefile.am | 2 ++
tests/delegates/anonymous-dynamic.test | 15 +++++++++++++++
tests/delegates/anonymous-inner-params.test | 19 +++++++++++++++++++
tests/delegates/anonymous-params.test | 18 +++++++-----------
vala/valaparser.vala | 17 +++++++++++++----
5 files changed, 56 insertions(+), 15 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 8675e401a..c4796938b 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -340,9 +340,11 @@ TESTS = \
structs/bug777194-2.vala \
delegates/anonymous.vala \
delegates/anonymous-array.vala \
+ delegates/anonymous-dynamic.test \
delegates/anonymous-generics.test \
delegates/anonymous-inner-dynamic-param.test \
delegates/anonymous-inner-dynamic-return.test \
+ delegates/anonymous-inner-params.test \
delegates/anonymous-inner-ref-out.vala \
delegates/anonymous-inner-owned-unowned.vala \
delegates/anonymous-optional-param.test \
diff --git a/tests/delegates/anonymous-dynamic.test b/tests/delegates/anonymous-dynamic.test
new file mode 100644
index 000000000..f067c1d47
--- /dev/null
+++ b/tests/delegates/anonymous-dynamic.test
@@ -0,0 +1,15 @@
+Invalid Code
+
+/*
+ * 9.8-9.32: error: Anonymous delegates cannot be dynamic types
+ * void p(dynamic delegate() => int d) {
+ * ^^^^^^^^^^^^^^^^^^^^^^^^^
+ */
+
+void p(dynamic delegate() => int d) {
+ d ();
+}
+
+void main () {
+ p (() => 7);
+}
diff --git a/tests/delegates/anonymous-inner-params.test b/tests/delegates/anonymous-inner-params.test
new file mode 100644
index 000000000..4dcb3e698
--- /dev/null
+++ b/tests/delegates/anonymous-inner-params.test
@@ -0,0 +1,19 @@
+Invalid Code
+
+/*
+ * 13.18-13.23: error: Params-arrays not allowed in anonymous delegates
+ * void f (delegate(params string[]) => void y) {
+ * ^^^^^^
+ */
+
+void main () {
+ f (t);
+}
+
+void f (delegate(params string[]) => void y) {
+ y ("1", "2", "3");
+}
+
+void t (params string[] p) {
+ assert (p.length == 3);
+}
diff --git a/tests/delegates/anonymous-params.test b/tests/delegates/anonymous-params.test
index 4dcb3e698..4772114bd 100644
--- a/tests/delegates/anonymous-params.test
+++ b/tests/delegates/anonymous-params.test
@@ -1,19 +1,15 @@
Invalid Code
/*
- * 13.18-13.23: error: Params-arrays not allowed in anonymous delegates
- * void f (delegate(params string[]) => void y) {
- * ^^^^^^
+ * 9.9-9.32: error: Anonymous delegates cannot be param-arrays
+ * void p (params delegate() => int d) {
+ * ^^^^^^^^^^^^^^^^^^^^^^^^
*/
-void main () {
- f (t);
-}
-
-void f (delegate(params string[]) => void y) {
- y ("1", "2", "3");
+void p (params delegate() => int d) {
+ d ();
}
-void t (params string[] p) {
- assert (p.length == 3);
+void main () {
+ return;
}
diff --git a/vala/valaparser.vala b/vala/valaparser.vala
index b9143c0b3..576256e25 100644
--- a/vala/valaparser.vala
+++ b/vala/valaparser.vala
@@ -514,6 +514,7 @@ public class Vala.Parser : CodeVisitor {
rollback (begin2);
type = parse_anonymous_delegate (parent, method);
type.value_owned = value_owned;
+ type.is_dynamic = is_dynamic;
return type;
} else {
rollback (begin2);
@@ -3565,10 +3566,18 @@ public class Vala.Parser : CodeVisitor {
}
var possibly_delegate = type as DelegateType;
- if (possibly_delegate != null
- && possibly_delegate.delegate_symbol.anonymous
- && pretty_direction != null) {
- Report.error (get_src (begin), "Anonymous delegates cannot be `" + pretty_direction +
"` parameters");
+ if (possibly_delegate != null && possibly_delegate.delegate_symbol.anonymous) {
+ if (pretty_direction != null) {
+ Report.error (get_src (begin), "Anonymous delegates cannot be `" +
pretty_direction + "` parameters");
+ }
+
+ if (possibly_delegate.is_dynamic) {
+ Report.error (get_src (begin), "Anonymous delegates cannot be dynamic types");
+ }
+
+ if (params_array) {
+ Report.error (get_src (begin), "Anonymous delegates cannot be param-arrays");
+ }
}
string id = parse_identifier ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]