Skip to content

Commit 8449bdf

Browse files
authored
Merge pull request #334 from ichiban/avoid-recursive-load
avoid recursive file load.
2 parents 3223b40 + c33bef0 commit 8449bdf

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

engine/text.go

+9-4
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,16 @@ func (vm *VM) ensureLoaded(ctx context.Context, file Term, env *Env) error {
192192
if _, ok := vm.loaded[f]; ok {
193193
return nil
194194
}
195-
defer func() {
196-
vm.loaded[f] = struct{}{}
197-
}()
198195

199-
return vm.Compile(ctx, string(b))
196+
// It's too early to say it's fully loaded. Yet this avoids recursive load of the same file.
197+
vm.loaded[f] = struct{}{}
198+
199+
if err := vm.Compile(ctx, string(b)); err != nil {
200+
delete(vm.loaded, f) // It wasn't fully loaded after all.
201+
return err
202+
}
203+
204+
return nil
200205
}
201206

202207
func (vm *VM) open(file Term, env *Env) (string, []byte, error) {

0 commit comments

Comments
 (0)