[vala/wip/issue/658: 42/48] Forbid inner dynamic types for anonymous delegates
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/issue/658: 42/48] Forbid inner dynamic types for anonymous delegates
- Date: Sat, 31 Oct 2020 15:08:17 +0000 (UTC)
commit 706650d50048da1691da078709e136c7966a66d2
Author: Nick Schrader <nick schrader mailbox org>
Date: Wed Oct 28 20:17:53 2020 -0300
Forbid inner dynamic types for anonymous delegates
tests/Makefile.am | 2 ++
tests/delegates/anonymous-inner-dynamic-param.test | 15 +++++++++++++++
tests/delegates/anonymous-inner-dynamic-return.test | 15 +++++++++++++++
vala/valaparser.vala | 10 ++++++++++
4 files changed, 42 insertions(+)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 8c5e23412..8675e401a 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -341,6 +341,8 @@ TESTS = \
delegates/anonymous.vala \
delegates/anonymous-array.vala \
delegates/anonymous-generics.test \
+ delegates/anonymous-inner-dynamic-param.test \
+ delegates/anonymous-inner-dynamic-return.test \
delegates/anonymous-inner-ref-out.vala \
delegates/anonymous-inner-owned-unowned.vala \
delegates/anonymous-optional-param.test \
diff --git a/tests/delegates/anonymous-inner-dynamic-param.test
b/tests/delegates/anonymous-inner-dynamic-param.test
new file mode 100644
index 000000000..3f3fca197
--- /dev/null
+++ b/tests/delegates/anonymous-inner-dynamic-param.test
@@ -0,0 +1,15 @@
+Invalid Code
+
+/*
+ * 7.17-7.27: error: Dynamic types not allowed in anonymous delegates
+ * void p(delegate(dynamic int) => void d) {
+ * ^^^^^^^^^^^
+ */
+
+void p(delegate(dynamic int) => void d) {
+ d (7);
+}
+
+void main () {
+ return;
+}
diff --git a/tests/delegates/anonymous-inner-dynamic-return.test
b/tests/delegates/anonymous-inner-dynamic-return.test
new file mode 100644
index 000000000..0c01de55e
--- /dev/null
+++ b/tests/delegates/anonymous-inner-dynamic-return.test
@@ -0,0 +1,15 @@
+Invalid Code
+
+/*
+ * 9.22-9.32: error: Dynamic types not allowed in anonymous delegates
+ * void p(delegate() => dynamic int d) {
+ * ^^^^^^^^^^^
+ */
+
+void p(delegate() => dynamic int d) {
+ var x = d ();
+}
+
+void main () {
+ return;
+}
diff --git a/vala/valaparser.vala b/vala/valaparser.vala
index 785cb206c..b9143c0b3 100644
--- a/vala/valaparser.vala
+++ b/vala/valaparser.vala
@@ -3723,6 +3723,7 @@ public class Vala.Parser : CodeVisitor {
}
DataType type;
+ var type_loc = get_location ();
if (direction == ParameterDirection.IN) {
// in parameters are unowned by default
type = parse_type (false, false);
@@ -3734,6 +3735,10 @@ public class Vala.Parser : CodeVisitor {
type = parse_type (true, false);
}
+ if (type.is_dynamic) {
+ Report.error (get_src (type_loc), "Dynamic types not allowed in anonymous delegates");
+ }
+
type = parse_inline_array_type (type);
if (accept (TokenType.ASSIGN)) {
@@ -3762,8 +3767,13 @@ public class Vala.Parser : CodeVisitor {
expect (TokenType.CLOSE_PARENS);
expect (TokenType.LAMBDA);
+ var type_loc = get_location ();
var type = parse_type (true, false);
+ if (type.is_dynamic) {
+ Report.error (get_src (type_loc), "Dynamic types not allowed in anonymous delegates");
+ }
+
var src = get_src (begin);
if (!context.experimental) {
Report.warning (src, "Anonymous delegates are experimental");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]