Skip to content

Commit

Permalink
Copy the AST before type-checking to avoid concurrency issues (#887)
Browse files Browse the repository at this point in the history
  • Loading branch information
TristonianJones authored Jan 23, 2024
1 parent 38d2641 commit a53bdc9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
5 changes: 2 additions & 3 deletions checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
4 changes: 2 additions & 2 deletions checker/checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down Expand Up @@ -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))
}
Expand Down

0 comments on commit a53bdc9

Please sign in to comment.