diff --git a/pkg/eval/builtin_special.go b/pkg/eval/builtin_special.go index 00f6bb56..3630cdbc 100644 --- a/pkg/eval/builtin_special.go +++ b/pkg/eval/builtin_special.go @@ -90,7 +90,7 @@ func compileVar(cp *compiler, fn *parse.Form) effectOp { } name := pn.Value - if strings.Contains(name, NsSuffix) { + if !IsUnqualified(name) { cp.errorpf(cn, "variable declared in var must be unqualified") } sigil, name := SplitSigil(name) @@ -108,6 +108,12 @@ func compileVar(cp *compiler, fn *parse.Form) effectOp { return nopOp{} } +// IsUnqualified returns whether name is an unqualified variable name. +func IsUnqualified(name string) bool { + i := strings.IndexByte(name, ':') + return i == -1 || i == len(name)-1 +} + // SetForm = 'set' { LHS } '=' { Compound } func compileSet(cp *compiler, fn *parse.Form) effectOp { eq := -1 diff --git a/pkg/eval/builtin_special_test.go b/pkg/eval/builtin_special_test.go index 4c034a6b..44889cf4 100644 --- a/pkg/eval/builtin_special_test.go +++ b/pkg/eval/builtin_special_test.go @@ -20,6 +20,8 @@ func TestVar(t *testing.T) { That("var x", "put $x").Puts(nil), // Declaring one variable whose name needs to be quoted That("var 'a/b'", "put $'a/b'").Puts(nil), + // Declaring one variable whose name ends in ":". + That("var a:").DoesNothing(), // Declaring multiple variables That("var x y", "put $x $y").Puts(nil, nil), // Declaring one variable with initial value