diff options
author | alandonovan <adonovan@google.com> | 2018-12-12 17:14:58 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-12 17:14:58 -0500 |
commit | b7e3b1f99d5ee0a686599bc14c3eb8ec40153829 (patch) | |
tree | 386ce9311a7a484bac08a5e26ca2b978f4735157 /syntax | |
parent | f50f3597ed1704298a6060aa314fe8521c490cce (diff) | |
download | starlark-go-b7e3b1f99d5ee0a686599bc14c3eb8ec40153829.tar.gz |
resolve: improve function parameter validation errors (#64)
Also, refactor setArgs by handling nullary case at top and outdenting the rest.
Diffstat (limited to 'syntax')
-rw-r--r-- | syntax/parse.go | 2 | ||||
-rw-r--r-- | syntax/testdata/errors.star | 18 |
2 files changed, 15 insertions, 5 deletions
diff --git a/syntax/parse.go b/syntax/parse.go index 82c6ab0..af79cc1 100644 --- a/syntax/parse.go +++ b/syntax/parse.go @@ -11,7 +11,7 @@ package syntax // package. Verify that error positions are correct using the // chunkedfile mechanism. -import log "log" +import "log" // Enable this flag to print the token stream and log.Fatal on the first error. const debug = false diff --git a/syntax/testdata/errors.star b/syntax/testdata/errors.star index 558845c..6ff3ea6 100644 --- a/syntax/testdata/errors.star +++ b/syntax/testdata/errors.star @@ -27,6 +27,12 @@ def f(**kwargs, ): ### `got '\)', want parameter` --- +# Parameters are validated later. +def f(**kwargs, *args, b=1, a, **kwargs, *args, b=1, a): + pass + +--- + def pass(): ### "not an identifier" pass @@ -48,6 +54,10 @@ f(**kwargs, ) ### `got '\)', want argument` --- +f(a=1, *, b=2) ### `got ',', want primary` + +--- + _ = {x:y for y in z} # ok _ = {x for y in z} ### `got for, want ':'` @@ -109,7 +119,7 @@ _ = 0 == 1 == 2 ### "== does not associate with ==" --- _ = (0 <= i) < n # ok -_ = 0 <= (i < n) # ok +_ = 0 <= (i < n) # ok _ = 0 <= i < n ### "<= does not associate with <" --- @@ -152,14 +162,14 @@ load("a", x2="x", "y") # => positional-before-named arg check happens later (!) # 'load' is not an identifier load = 1 ### `got '=', want '\('` --- -# 'load' is not an identifier +# 'load' is not an identifier f(load()) ### `got load, want primary` --- -# 'load' is not an identifier +# 'load' is not an identifier def load(): ### `not an identifier` pass --- -# 'load' is not an identifier +# 'load' is not an identifier def f(load): ### `not an identifier` pass --- |