From a53bdc97edfa61e8f7b3a29dec0a0d9061adb5b0 Mon Sep 17 00:00:00 2001 From: Tristan Swadell Date: Tue, 23 Jan 2024 15:05:45 -0800 Subject: [PATCH] Copy the AST before type-checking to avoid concurrency issues (#887) --- checker/checker.go | 5 ++--- checker/checker_test.go | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/checker/checker.go b/checker/checker.go index 57fb3ce5..8870739e 100644 --- a/checker/checker.go +++ b/checker/checker.go @@ -48,10 +48,9 @@ type checker struct { // registry. func Check(parsed *ast.AST, source common.Source, env *Env) (*ast.AST, *common.Errors) { errs := common.NewErrors(source) - typeMap := make(map[int64]*types.Type) - refMap := make(map[int64]*ast.ReferenceInfo) + checked := ast.Copy(parsed) c := checker{ - AST: ast.NewCheckedAST(parsed, typeMap, refMap), + AST: checked, ExprFactory: ast.NewExprFactory(), env: env, errors: &typeErrors{errs: errs}, diff --git a/checker/checker_test.go b/checker/checker_test.go index ac258884..ac5bbd5b 100644 --- a/checker/checker_test.go +++ b/checker/checker_test.go @@ -2413,7 +2413,7 @@ func TestCheck(t *testing.T) { } if tc.out != "" { - actualStr := Print(pAst.Expr(), cAst) + actualStr := Print(cAst.Expr(), cAst) if !test.Compare(actualStr, tc.out) { t.Error(test.DiffMessage("Structure error", actualStr, tc.out)) } @@ -2504,7 +2504,7 @@ func BenchmarkCheck(b *testing.B) { } if tc.out != "" { - actualStr := Print(pAst.Expr(), cAst) + actualStr := Print(cAst.Expr(), cAst) if !test.Compare(actualStr, tc.out) { b.Error(test.DiffMessage("Structure error", actualStr, tc.out)) }