diff options
author | alandonovan <adonovan@google.com> | 2020-11-11 14:23:03 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-11 14:23:03 -0500 |
commit | 6905482ffb8d09e875d4e87f3290493251aa565e (patch) | |
tree | 229d5f09a2b3d05d042c3144a81ce3970384890c | |
parent | 3b7e02ecde8b80808c06c8284ce9f85c101fcebd (diff) | |
download | starlark-go-6905482ffb8d09e875d4e87f3290493251aa565e.tar.gz |
starlark: disallow None < None comparisons (#314)
See spec change https://github.com/bazelbuild/starlark/issues/116
-rw-r--r-- | starlark/eval_test.go | 4 | ||||
-rw-r--r-- | starlark/testdata/misc.star | 1 | ||||
-rw-r--r-- | starlark/value.go | 4 |
3 files changed, 3 insertions, 6 deletions
diff --git a/starlark/eval_test.go b/starlark/eval_test.go index 13876a7..00b6e6d 100644 --- a/starlark/eval_test.go +++ b/starlark/eval_test.go @@ -509,7 +509,7 @@ func TestBacktrace(t *testing.T) { // functions, including propagation through built-ins such as 'min'. const src = ` def f(x): return 1//x -def g(x): f(x) +def g(x): return f(x) def h(): return min([1, 2, 0], key=g) def i(): return h() i() @@ -522,7 +522,7 @@ i() crash.star:5:18: in i crash.star:4:20: in h <builtin>: in min - crash.star:3:12: in g + crash.star:3:19: in g crash.star:2:19: in f Error: floored division by zero` if got := backtrace(t, err); got != want { diff --git a/starlark/testdata/misc.star b/starlark/testdata/misc.star index 84ef84c..e7e0c06 100644 --- a/starlark/testdata/misc.star +++ b/starlark/testdata/misc.star @@ -39,6 +39,7 @@ load("assert.star", "assert") # Ordered comparisons require values of the same type. +assert.fails(lambda: None < None, "not impl") assert.fails(lambda: None < False, "not impl") assert.fails(lambda: False < list, "not impl") assert.fails(lambda: list < {}, "not impl") diff --git a/starlark/value.go b/starlark/value.go index 8d1b88a..bcec750 100644 --- a/starlark/value.go +++ b/starlark/value.go @@ -132,7 +132,6 @@ type Comparable interface { } var ( - _ Comparable = None _ Comparable = Int{} _ Comparable = False _ Comparable = Float(0) @@ -354,9 +353,6 @@ func (NoneType) Type() string { return "NoneType" } func (NoneType) Freeze() {} // immutable func (NoneType) Truth() Bool { return False } func (NoneType) Hash() (uint32, error) { return 0, nil } -func (NoneType) CompareSameType(op syntax.Token, y Value, depth int) (bool, error) { - return threeway(op, 0), nil -} // Bool is the type of a Starlark bool. type Bool bool |