Skip to content

Commit a53bdc9

Browse files
Copy the AST before type-checking to avoid concurrency issues (#887)
1 parent 38d2641 commit a53bdc9

2 files changed

Lines changed: 4 additions & 5 deletions

File tree

checker/checker.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,9 @@ type checker struct {
4848
// registry.
4949
func Check(parsed *ast.AST, source common.Source, env *Env) (*ast.AST, *common.Errors) {
5050
errs := common.NewErrors(source)
51-
typeMap := make(map[int64]*types.Type)
52-
refMap := make(map[int64]*ast.ReferenceInfo)
51+
checked := ast.Copy(parsed)
5352
c := checker{
54-
AST: ast.NewCheckedAST(parsed, typeMap, refMap),
53+
AST: checked,
5554
ExprFactory: ast.NewExprFactory(),
5655
env: env,
5756
errors: &typeErrors{errs: errs},

checker/checker_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2413,7 +2413,7 @@ func TestCheck(t *testing.T) {
24132413
}
24142414

24152415
if tc.out != "" {
2416-
actualStr := Print(pAst.Expr(), cAst)
2416+
actualStr := Print(cAst.Expr(), cAst)
24172417
if !test.Compare(actualStr, tc.out) {
24182418
t.Error(test.DiffMessage("Structure error", actualStr, tc.out))
24192419
}
@@ -2504,7 +2504,7 @@ func BenchmarkCheck(b *testing.B) {
25042504
}
25052505

25062506
if tc.out != "" {
2507-
actualStr := Print(pAst.Expr(), cAst)
2507+
actualStr := Print(cAst.Expr(), cAst)
25082508
if !test.Compare(actualStr, tc.out) {
25092509
b.Error(test.DiffMessage("Structure error", actualStr, tc.out))
25102510
}

0 commit comments

Comments
 (0)