aboutsummaryrefslogtreecommitdiff
path: root/resolve
diff options
context:
space:
mode:
authoralandonovan <adonovan@google.com>2021-01-21 17:58:09 -0500
committerGitHub <noreply@github.com>2021-01-21 17:58:09 -0500
commitcea917ab6e0f5d6548d516f8c30e197d63db9baa (patch)
tree899c6a22cc01630d69f93cb014987daed5e98208 /resolve
parentfb04d37e5d7fe9cdcc59adfcfd94d1863ac6cb38 (diff)
downloadstarlark-go-cea917ab6e0f5d6548d516f8c30e197d63db9baa.tar.gz
resolver: make -nesteddef and -lambda always on (#328)
See https://github.com/bazelbuild/starlark/pull/145 for spec changes. Updates https://github.com/bazelbuild/starlark/issues/20
Diffstat (limited to 'resolve')
-rw-r--r--resolve/resolve.go16
-rw-r--r--resolve/resolve_test.go4
-rw-r--r--resolve/testdata/resolve.star2
3 files changed, 8 insertions, 14 deletions
diff --git a/resolve/resolve.go b/resolve/resolve.go
index 8c1b730..56e33ba 100644
--- a/resolve/resolve.go
+++ b/resolve/resolve.go
@@ -98,14 +98,16 @@ const doesnt = "this Starlark dialect does not "
// These features are either not standard Starlark (yet), or deprecated
// features of the BUILD language, so we put them behind flags.
var (
- AllowNestedDef = false // allow def statements within function bodies
- AllowLambda = false // allow lambda expressions
- AllowFloat = false // obsolete; no effect
AllowSet = false // allow the 'set' built-in
AllowGlobalReassign = false // allow reassignment to top-level names; also, allow if/for/while at top-level
AllowRecursion = false // allow while statements and recursive functions
- AllowBitwise = true // obsolete; bitwise operations (&, |, ^, ~, <<, and >>) are always enabled
LoadBindsGlobally = false // load creates global not file-local bindings (deprecated)
+
+ // obsolete flags for features that are now standard. No effect.
+ AllowNestedDef = true
+ AllowLambda = true
+ AllowFloat = true
+ AllowBitwise = true
)
// File resolves the specified file and records information about the
@@ -506,9 +508,6 @@ func (r *resolver) stmt(stmt syntax.Stmt) {
r.assign(stmt.LHS, isAugmented)
case *syntax.DefStmt:
- if !AllowNestedDef && r.container().function != nil {
- r.errorf(stmt.Def, doesnt+"support nested def")
- }
r.bind(stmt.Name)
fn := &Function{
Name: stmt.Name.Name,
@@ -780,9 +779,6 @@ func (r *resolver) expr(e syntax.Expr) {
}
case *syntax.LambdaExpr:
- if !AllowLambda {
- r.errorf(e.Lambda, doesnt+"support lambda")
- }
fn := &Function{
Name: "lambda",
Pos: e.Lambda,
diff --git a/resolve/resolve_test.go b/resolve/resolve_test.go
index cb2c672..50d1cc5 100644
--- a/resolve/resolve_test.go
+++ b/resolve/resolve_test.go
@@ -16,8 +16,6 @@ import (
func setOptions(src string) {
resolve.AllowGlobalReassign = option(src, "globalreassign")
- resolve.AllowLambda = option(src, "lambda")
- resolve.AllowNestedDef = option(src, "nesteddef")
resolve.AllowRecursion = option(src, "recursion")
resolve.AllowSet = option(src, "set")
resolve.LoadBindsGlobally = option(src, "loadbindsglobally")
@@ -37,7 +35,7 @@ func TestResolve(t *testing.T) {
continue
}
- // A chunk may set options by containing e.g. "option:nesteddef".
+ // A chunk may set options by containing e.g. "option:recursion".
setOptions(chunk.Source)
if err := resolve.File(f, isPredeclared, isUniversal); err != nil {
diff --git a/resolve/testdata/resolve.star b/resolve/testdata/resolve.star
index fb4c78e..ce67110 100644
--- a/resolve/testdata/resolve.star
+++ b/resolve/testdata/resolve.star
@@ -79,7 +79,7 @@ _ = [x for x in "abc"]
M(x) ### "undefined: x"
---
-# Functions may have forward refs. (option:lambda option:nesteddef)
+# Functions may have forward refs.
def f():
g()
h() ### "undefined: h"