diff options
| author | David Symonds <dsymonds@golang.org> | 2012-11-13 09:08:33 +1100 |
|---|---|---|
| committer | David Symonds <dsymonds@golang.org> | 2012-11-13 09:08:33 +1100 |
| commit | 80f4ff226ff8fb36ba3c8b4808982c6664ce47c3 (patch) | |
| tree | 1108deb9fbc10f04d23ed968352c7c5e7ddddfb8 /src/pkg/exp | |
| parent | c90739e41ebb7e0c0adc1bbdad61a08dc240dffe (diff) | |
| download | go-80f4ff226ff8fb36ba3c8b4808982c6664ce47c3.tar.xz | |
exp/types: avoid init race in check_test.go.
There was an init race between
check_test.go:init
universe.go:def
use of Universe
and
universe.go:init
creation of Universe
The order in which init funcs are executed in a package is unspecified.
The test is not currently broken in the golang.org environment
because the go tool compiles the test with non-test sources before test sources,
but other environments may, say, sort the source files before compiling,
and thus trigger this race, causing a nil pointer panic.
R=gri
CC=golang-dev
https://golang.org/cl/6827076
Diffstat (limited to 'src/pkg/exp')
| -rw-r--r-- | src/pkg/exp/types/check_test.go | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/pkg/exp/types/check_test.go b/src/pkg/exp/types/check_test.go index abcfcfb2cd..bfa4d2c2b1 100644 --- a/src/pkg/exp/types/check_test.go +++ b/src/pkg/exp/types/check_test.go @@ -37,12 +37,6 @@ import ( var listErrors = flag.Bool("list", false, "list errors") -func init() { - // declare builtins for testing - def(ast.Fun, "assert").Type = &builtin{aType, _Assert, "assert", 1, false, true} - def(ast.Fun, "trace").Type = &builtin{aType, _Trace, "trace", 0, true, true} -} - // The test filenames do not end in .go so that they are invisible // to gofmt since they contain comments that must not change their // positions relative to surrounding tokens. @@ -241,6 +235,12 @@ func checkFiles(t *testing.T, testname string, testfiles []string) { } func TestCheck(t *testing.T) { + // Declare builtins for testing. + // Not done in an init func to avoid an init race with + // the construction of the Universe var. + def(ast.Fun, "assert").Type = &builtin{aType, _Assert, "assert", 1, false, true} + def(ast.Fun, "trace").Type = &builtin{aType, _Trace, "trace", 0, true, true} + // For easy debugging w/o changing the testing code, // if there is a local test file, only test that file. const testfile = "testdata/test.go" |
