[vala/wip/issue/658: 34/34] Fixed crash: anonymous delegate returning a. del.
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/issue/658: 34/34] Fixed crash: anonymous delegate returning a. del.
- Date: Fri, 6 Nov 2020 11:17:09 +0000 (UTC)
commit c28cbf4e7bb70fc131e3f151e888c02e9fb5140c
Author: Nick Schrader <nick schrader mailbox org>
Date: Thu Nov 5 23:11:50 2020 -0300
Fixed crash: anonymous delegate returning a. del.
tests/Makefile.am | 1 +
tests/delegates/anonymous-return-anonymous.test | 18 ++++++++++++++++++
vala/valaparser.vala | 12 +++++++-----
3 files changed, 26 insertions(+), 5 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index b43ab00b9..16d9c3459 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -371,6 +371,7 @@ TESTS = \
delegates/anonymous-params.test \
delegates/anonymous-param-attrs.vala \
delegates/anonymous-ref.test \
+ delegates/anonymous-return-anonymous.test \
delegates/anonymous-throws.test \
delegates/anonymous-type-param.vala \
delegates/anonymous-variadic.test \
diff --git a/tests/delegates/anonymous-return-anonymous.test b/tests/delegates/anonymous-return-anonymous.test
new file mode 100644
index 000000000..47be7785f
--- /dev/null
+++ b/tests/delegates/anonymous-return-anonymous.test
@@ -0,0 +1,18 @@
+Invalid Code
+
+ /*
+ * 9.26-9.33: error: syntax error, anonymous delegate not allowed here
+ * void f (delegate(int) => delegate() => int d) {
+ * ^^^^^^^^
+ */
+
+void f (delegate(int) => delegate() => int d) {
+ var r = d (14);
+ stdout.printf("%d\n", r ());
+}
+
+void main () {
+ f ((a) => {
+ return () => a;
+ });
+}
diff --git a/vala/valaparser.vala b/vala/valaparser.vala
index 056289961..fcb6774b4 100644
--- a/vala/valaparser.vala
+++ b/vala/valaparser.vala
@@ -509,15 +509,17 @@ public class Vala.Parser : CodeVisitor {
DataType type;
- var begin2 = get_location ();
- if (accept (TokenType.DELEGATE)) {
- rollback (begin2);
+ var begin_delegate_token = get_location ();
+ var is_delegate_token = accept (TokenType.DELEGATE);
+ rollback (begin_delegate_token);
+
+ if (is_delegate_token && method == null) {
+ throw new ParseError.SYNTAX ("anonymous delegate not allowed here");
+ } else if (is_delegate_token) {
type = parse_anonymous_delegate (parent, method);
type.value_owned = value_owned;
type.is_dynamic = is_dynamic;
return type;
- } else {
- rollback (begin2);
}
bool inner_type_owned = true;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]