Skip to content

Commit

Permalink
starlark: add spell checking to load statement (google#177)
Browse files Browse the repository at this point in the history
  • Loading branch information
adonovan authored Mar 18, 2019
1 parent f223ef8 commit 885f8b8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions starlark/interp.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"

"go.starlark.net/internal/compile"
"go.starlark.net/internal/spell"
"go.starlark.net/resolve"
"go.starlark.net/syntax"
)
Expand Down Expand Up @@ -499,6 +500,9 @@ loop:
v, ok := dict[from]
if !ok {
err = fmt.Errorf("load: name %s not found in module %s", from, module)
if n := spell.Nearest(from, dict.Keys()); n != "" {
err = fmt.Errorf("%s (did you mean %s?)", err, n)
}
break loop
}
stack[sp-1-i] = v
Expand Down
5 changes: 5 additions & 0 deletions starlark/testdata/misc.star
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,8 @@ assert.eq([] + [1] + l + [2, 3], [1, 4, 2, 3])
assert.fails(lambda: "a" + "b" + 1 + "c", "unknown binary op: string \\+ int")
assert.fails(lambda: () + () + 1 + (), "unknown binary op: tuple \\+ int")
assert.fails(lambda: [] + [] + 1 + [], "unknown binary op: list \\+ int")



---
load('assert.star', 'froze') ### `name froze not found .*did you mean freeze`

0 comments on commit 885f8b8

Please sign in to comment.