diff --git a/starlark/interp.go b/starlark/interp.go index 0339aece..e0ecf687 100644 --- a/starlark/interp.go +++ b/starlark/interp.go @@ -7,6 +7,7 @@ import ( "os" "go.starlark.net/internal/compile" + "go.starlark.net/internal/spell" "go.starlark.net/resolve" "go.starlark.net/syntax" ) @@ -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 diff --git a/starlark/testdata/misc.star b/starlark/testdata/misc.star index b630ecc3..0cb973ab 100644 --- a/starlark/testdata/misc.star +++ b/starlark/testdata/misc.star @@ -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`