| 1 |
// run |
| 2 |
|
| 3 |
//go:build !js && !wasip1 |
| 4 |
|
| 5 |
// Copyright 2022 The Go Authors. All rights reserved. |
| 6 |
// Use of this source code is governed by a BSD-style |
| 7 |
// license that can be found in the LICENSE file. |
| 8 |
|
| 9 |
// Issue 52127: Too many syntax errors in many files can |
| 10 |
// cause deadlocks instead of displaying error messages |
| 11 |
// correctly. |
| 12 |
|
| 13 |
package main |
| 14 |
|
| 15 |
import ( |
| 16 |
"bytes" |
| 17 |
"fmt" |
| 18 |
"os" |
| 19 |
"os/exec" |
| 20 |
"path/filepath" |
| 21 |
) |
| 22 |
|
| 23 |
func main() { |
| 24 |
dir, err := os.MkdirTemp("", "issue52127") |
| 25 |
if err != nil { |
| 26 |
panic(err) |
| 27 |
} |
| 28 |
defer os.RemoveAll(dir) |
| 29 |
|
| 30 |
args := []string{"go", "build"} |
| 31 |
write := func(prefix string, i int, data string) { |
| 32 |
filename := filepath.Join(dir, fmt.Sprintf("%s%d.go", prefix, i)) |
| 33 |
if err := os.WriteFile(filename, []byte(data), 0o644); err != nil { |
| 34 |
panic(err) |
| 35 |
} |
| 36 |
args = append(args, filename) |
| 37 |
} |
| 38 |
|
| 39 |
for i := 0; i < 100; i++ { |
| 40 |
write("a", i, `package p |
| 41 |
`) |
| 42 |
} |
| 43 |
for i := 0; i < 100; i++ { |
| 44 |
write("b", i, `package p |
| 45 |
var |
| 46 |
var |
| 47 |
var |
| 48 |
var |
| 49 |
var |
| 50 |
`) |
| 51 |
} |
| 52 |
|
| 53 |
cmd := exec.Command(args[0], args[1:]...) |
| 54 |
output, err := cmd.CombinedOutput() |
| 55 |
if err == nil { |
| 56 |
panic("compile succeeded unexpectedly") |
| 57 |
} |
| 58 |
if !bytes.Contains(output, []byte("syntax error:")) { |
| 59 |
panic(fmt.Sprintf(`missing "syntax error" in compiler output; got: |
| 60 |
%s`, output)) |
| 61 |
} |
| 62 |
} |