typing: error on foo() when foo is a variable
authorJean Privat <jean@pryen.org>
Fri, 24 Feb 2012 19:26:11 +0000 (14:26 -0500)
committerJean Privat <jean@pryen.org>
Fri, 24 Feb 2012 19:26:11 +0000 (14:26 -0500)
With the last parser modification we can now distinguish between
no arguments and empty parentheses.

Signed-off-by: Jean Privat <jean@pryen.org>

src/syntax/typing.nit
tests/error_var_args3.nit [new file with mode: 0644]
tests/error_var_args4.nit [new file with mode: 0644]
tests/sav/error_var_args3.sav [new file with mode: 0644]
tests/sav/error_var_args4.sav [new file with mode: 0644]

index 4155ecc..0fb3def 100644 (file)
@@ -1849,7 +1849,7 @@ redef class ACallFormExpr
                                        n = new AClosureCallExpr.init_aclosurecallexpr(n_id, n_args, n_closure_defs)
                                        n._variable = variable
                                else
-                                       if not n_args.n_exprs.is_empty then
+                                       if not n_args.n_exprs.is_empty or n_args isa AParExprs then
                                                v.error(self, "Error: {name} is variable, not a function.")
                                                return
                                        end
diff --git a/tests/error_var_args3.nit b/tests/error_var_args3.nit
new file mode 100644 (file)
index 0000000..b93b55e
--- /dev/null
@@ -0,0 +1,18 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Copyright 2004-2008 Jean Privat <jean@pryen.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.
+
+var t: Int
+t()
diff --git a/tests/error_var_args4.nit b/tests/error_var_args4.nit
new file mode 100644 (file)
index 0000000..b16f971
--- /dev/null
@@ -0,0 +1,18 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Copyright 2004-2008 Jean Privat <jean@pryen.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.
+
+var t: Int
+t() = 12
diff --git a/tests/sav/error_var_args3.sav b/tests/sav/error_var_args3.sav
new file mode 100644 (file)
index 0000000..1683b26
--- /dev/null
@@ -0,0 +1 @@
+error_var_args3.nit:18,1--3: Error: t is variable, not a function.
diff --git a/tests/sav/error_var_args4.sav b/tests/sav/error_var_args4.sav
new file mode 100644 (file)
index 0000000..a3329e7
--- /dev/null
@@ -0,0 +1 @@
+error_var_args4.nit:18,1--8: Error: t is variable, not a function.