Parser warnings
Sidef provides the -k option which will keep track of all the possible unsafe parser interpretations.
For example, if we declare the following function, but we misspell its name when we call it, Sidef will interpret it as a method call, which is probably not what we want:
1
func foo(n) { say n }
2
fo(42) # will get interpreted as `42.fo`
Copied!
When the command-line option -k is specified, the following warning is produced:
1
[INFO] `fo` is parsed as a prefix method-call at script.sf line 2
Copied!
One simple way to catch this kind of errors at parse-time, it to always call functions with the explicit .call method:
1
func foo(n) { say n }
2
fo.call(42)
Copied!
The above code will fail to compile, producing the following error message:
1
File : test.sf
2
Line : 2
3
Error: variable <fo> is not declared in the current scope
4
5
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6
fo.call(42)
7
^
8
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9
[?] Did you mean: foo
Copied!
Last modified 1yr ago
Copy link