tests: add syntax_lambda to check various forms
authorJean Privat <jean@pryen.org>
Thu, 4 Jul 2019 19:36:10 +0000 (15:36 -0400)
committerJean Privat <jean@pryen.org>
Mon, 19 Aug 2019 13:11:45 +0000 (09:11 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

tests/sav/syntax_lambda.res [new file with mode: 0644]
tests/sav/syntax_lambda_alt1.res [new file with mode: 0644]
tests/sav/syntax_lambda_alt2.res [new file with mode: 0644]
tests/syntax_lambda.nit [new file with mode: 0644]

diff --git a/tests/sav/syntax_lambda.res b/tests/sav/syntax_lambda.res
new file mode 100644 (file)
index 0000000..399d840
--- /dev/null
@@ -0,0 +1 @@
+syntax_lambda.nit:36,1--28: Error: unreachable statement.
diff --git a/tests/sav/syntax_lambda_alt1.res b/tests/sav/syntax_lambda_alt1.res
new file mode 100644 (file)
index 0000000..13c981f
--- /dev/null
@@ -0,0 +1 @@
+alt/syntax_lambda_alt1.nit:65,1: Syntax Error: unexpected end of file.
diff --git a/tests/sav/syntax_lambda_alt2.res b/tests/sav/syntax_lambda_alt2.res
new file mode 100644 (file)
index 0000000..0c1ef9a
--- /dev/null
@@ -0,0 +1 @@
+alt/syntax_lambda_alt2.nit:29,25: Syntax Error: unexpected ')'.
diff --git a/tests/syntax_lambda.nit b/tests/syntax_lambda.nit
new file mode 100644 (file)
index 0000000..7302d4a
--- /dev/null
@@ -0,0 +1,64 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+class A
+       fun foo(any: Object) do end
+end
+
+class B
+end
+
+fun bar(any: Object) do end
+
+var a = fun do end
+
+var b = fun do print 1 end
+#alt1# var b2 = fun do print 1 # mandatory end
+var b3 = (fun do print 1 end)
+#alt2# var b3 = (fun do print 1) # still mandatory end
+
+var c = fun do
+       print 1
+       return
+end
+
+var d = fun(a: A) do print 1 end
+var d2 = fun(a) do print 1 end # might be a sematic error but is legal syntax
+
+var e = fun: A do return new A end
+
+var f = fun(a: A, b: B...): C do return a.foo(b) end
+
+var g = [fun: Int do return 1 end, fun: Int do return 2 end]
+
+bar(fun do print 1 end)
+bar fun do print 1 end
+
+bar(
+fun
+do
+       print 1
+end
+)
+
+(fun do print 1 end).bar
+fun do print 1 end.bar # this is unexpectedly legal
+
+var z = fun do
+       return fun do
+               return 1
+       end
+end
+
+fun do fun do end.foo fun do end end.bar # hmmm