Skip to content
This repository has been archived by the owner on Aug 15, 2023. It is now read-only.

Commit

Permalink
starlark: disallow None < None comparisons (google#314)
Browse files Browse the repository at this point in the history
See spec change bazelbuild/starlark#116
  • Loading branch information
adonovan authored Nov 11, 2020
1 parent 3b7e02e commit 6905482
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 6 deletions.
4 changes: 2 additions & 2 deletions starlark/eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions starlark/testdata/misc.star
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 0 additions & 4 deletions starlark/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ type Comparable interface {
}

var (
_ Comparable = None
_ Comparable = Int{}
_ Comparable = False
_ Comparable = Float(0)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6905482

Please sign in to comment.