Skip to content
This repository was archived by the owner on Mar 23, 2023. It is now read-only.

runtime: Fix complain about linting and Go 1.9 compiler error. #384

Merged
merged 2 commits into from
Nov 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ language: go
os:
- linux
- osx
before_script:
- rvm get head || true # https://github.com/travis-ci/travis-ci/issues/6307
- set -e
# Run gofmt and lint serially to avoid confusing output. Run tests in parallel
# for speed.
script: make gofmt lint && make -j2 test
after_script: set +e
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ endif
PYTHON_BIN := $(shell which $(PYTHON))
PYTHON_VER := $(word 2,$(shell $(PYTHON) -V 2>&1))
GO_REQ_MAJ := 1
GO_REQ_MIN := 6
GO_REQ_MIN := 9
GO_MAJ_MIN := $(subst go,, $(word 3,$(shell go version 2>&1)) )
GO_MAJ := $(word 1,$(subst ., ,$(GO_MAJ_MIN) ))
GO_MIN := $(word 2,$(subst ., ,$(GO_MAJ_MIN) ))
Expand Down
2 changes: 1 addition & 1 deletion runtime/complex.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ func complexModOp(v, w complex128) complex128 {
}

const (
_ = iota
blank = iota
real1
imag1
real2
Expand Down
12 changes: 8 additions & 4 deletions runtime/complex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ func TestComplexEq(t *testing.T) {
}
}

// FIXME(corona10): Since Go 1.9 moved to C99 float division and what CPython uses as well.
// Some tests can be failed with version < Go 1.9. We need to detect Go version.
// And changed expected values.

func TestComplexBinaryOps(t *testing.T) {
cases := []struct {
fun func(f *Frame, v, w *Object) (*Object, *BaseException)
Expand Down Expand Up @@ -107,8 +111,8 @@ func TestComplexBinaryOps(t *testing.T) {
{Div, NewComplex(3 - 4i).ToObject(), NewLong(big.NewInt(-34)).ToObject(), NewComplex(-0.08823529411764706 + 0.11764705882352941i).ToObject(), nil},
{Div, NewComplex(3 + 4i).ToObject(), NewComplex(complex(math.Inf(1), math.Inf(-1))).ToObject(), NewComplex(0i).ToObject(), nil},
{Div, NewComplex(3 + 4i).ToObject(), NewComplex(complex(math.Inf(1), 2)).ToObject(), NewComplex(0i).ToObject(), nil},
{Div, NewComplex(complex(math.Inf(1), math.Inf(1))).ToObject(), NewComplex(1 + 2i).ToObject(), NewComplex(complex(math.Inf(1), math.Inf(1))).ToObject(), nil},
{Div, NewComplex(complex(math.Inf(1), 4)).ToObject(), NewComplex(1 + 2i).ToObject(), NewComplex(complex(math.Inf(1), math.Inf(1))).ToObject(), nil},
{Div, NewComplex(complex(math.Inf(1), math.Inf(1))).ToObject(), NewComplex(1 + 2i).ToObject(), NewComplex(complex(math.Inf(1), math.NaN())).ToObject(), nil},
{Div, NewComplex(complex(math.Inf(1), 4)).ToObject(), NewComplex(1 + 2i).ToObject(), NewComplex(complex(math.Inf(1), math.Inf(-1))).ToObject(), nil},
{Div, NewComplex(complex(3, math.Inf(1))).ToObject(), NewComplex(1 + 2i).ToObject(), NewComplex(complex(math.Inf(1), math.Inf(1))).ToObject(), nil},
{Div, NewComplex(complex(3, math.NaN())).ToObject(), NewComplex(1 + 2i).ToObject(), NewComplex(complex(math.NaN(), math.NaN())).ToObject(), nil},
{Div, NewStr("foo").ToObject(), NewComplex(1 + 2i).ToObject(), nil, mustCreateException(TypeErrorType, "unsupported operand type(s) for /: 'str' and 'complex'")},
Expand Down Expand Up @@ -189,8 +193,8 @@ func TestComplexBinaryOps(t *testing.T) {
{Pow, NewComplex(complex(math.Inf(-1), 2)).ToObject(), NewComplex(1 + 2i).ToObject(), NewComplex(complex(math.NaN(), math.NaN())).ToObject(), nil},
{Pow, NewComplex(1 + 2i).ToObject(), NewComplex(complex(1, math.Inf(1))).ToObject(), NewComplex(complex(math.NaN(), math.NaN())).ToObject(), nil},
{Pow, NewComplex(complex(math.NaN(), 1)).ToObject(), NewComplex(3 + 4i).ToObject(), NewComplex(complex(math.NaN(), math.NaN())).ToObject(), nil},
{Pow, NewComplex(3 + 4i).ToObject(), NewInt(3).ToObject(), NewComplex(-117 + 44.000000000000036i).ToObject(), nil},
{Pow, NewComplex(3 + 4i).ToObject(), NewFloat(3.1415).ToObject(), NewComplex(-152.8892667678244 + 35.55533513049651i).ToObject(), nil},
{Pow, NewComplex(3 + 4i).ToObject(), NewInt(3).ToObject(), NewComplex(-117 + 44.00000000000003i).ToObject(), nil},
{Pow, NewComplex(3 + 4i).ToObject(), NewFloat(3.1415).ToObject(), NewComplex(-152.8892667678244 + 35.555335130496516i).ToObject(), nil},
{Pow, NewComplex(3 + 4i).ToObject(), NewLong(big.NewInt(123)).ToObject(), NewComplex(5.393538720276193e+85 + 7.703512580443326e+85i).ToObject(), nil},
{Pow, NewComplex(1 + 2i).ToObject(), NewStr("foo").ToObject(), nil, mustCreateException(TypeErrorType, "unsupported operand type(s) for **: 'complex' and 'str'")},
{Pow, NewStr("foo").ToObject(), NewComplex(1 + 2i).ToObject(), nil, mustCreateException(TypeErrorType, "unsupported operand type(s) for **: 'str' and 'complex'")},
Expand Down
6 changes: 3 additions & 3 deletions runtime/dict.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func (iter *dictEntryIterator) next() *dictEntry {
// 64bit atomic ops need to be 8 byte aligned. This compile time check
// verifies alignment by creating a negative constant for an unsigned type.
// See sync/atomic docs for details.
const _ = -(unsafe.Offsetof(iter.index) % 8)
const blank = -(unsafe.Offsetof(iter.index) % 8)
index := int(atomic.AddInt64(&iter.index, 1)) - 1
if index >= numEntries {
break
Expand Down Expand Up @@ -310,7 +310,7 @@ func (d *Dict) loadVersion() int64 {
// 64bit atomic ops need to be 8 byte aligned. This compile time check
// verifies alignment by creating a negative constant for an unsigned type.
// See sync/atomic docs for details.
const _ = -(unsafe.Offsetof(d.version) % 8)
const blank = -(unsafe.Offsetof(d.version) % 8)
return atomic.LoadInt64(&d.version)
}

Expand All @@ -319,7 +319,7 @@ func (d *Dict) incVersion() {
// 64bit atomic ops need to be 8 byte aligned. This compile time check
// verifies alignment by creating a negative constant for an unsigned type.
// See sync/atomic docs for details.
const _ = -(unsafe.Offsetof(d.version) % 8)
const blank = -(unsafe.Offsetof(d.version) % 8)
atomic.AddInt64(&d.version, 1)
}

Expand Down
2 changes: 1 addition & 1 deletion runtime/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func TestFileCloseExit(t *testing.T) {
cases := []invokeTestCase{
{args: wrapArgs(newObject(FileType)), want: None},
{args: wrapArgs(f.open("r")), want: None},
{args: wrapArgs(closedFile), wantExc: mustCreateException(IOErrorType, "invalid argument")},
{args: wrapArgs(closedFile), wantExc: mustCreateException(IOErrorType, closedFile.file.Close().Error())},
}
for _, cas := range cases {
if err := runInvokeMethodTestCase(FileType, method, &cas); err != "" {
Expand Down
5 changes: 1 addition & 4 deletions runtime/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,7 @@ func (s *Set) ToObject() *Object {
// Update inserts all elements in the iterable o into s.
func (s *Set) Update(f *Frame, o *Object) *BaseException {
raised := seqForEach(f, o, func(key *Object) *BaseException {
if raised := s.dict.SetItem(f, key, None); raised != nil {
return raised
}
return nil
return s.dict.SetItem(f, key, None)
})
return raised
}
Expand Down