Skip to content

Commit

Permalink
fix the loop/review comment - add failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
ldemailly committed Sep 3, 2024
1 parent ba60055 commit 2a94511
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
4 changes: 4 additions & 0 deletions main_test.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,10 @@ stdout '^8$'
grol -quiet -c 'v=42;func foo(){v:=v;v=8};println(foo()); v'
stdout '^8\n42$'

# crash on self ref
grol -quiet -c 'v=42;func foo(){v=v}; foo()'
stdout '^42$'

-- json_output --
{
"63": 63,
Expand Down
21 changes: 13 additions & 8 deletions object/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,16 +179,21 @@ func (e *Environment) makeRef(name string) (*Reference, bool) {
orig := e
for e.outer != nil {
obj, ok := e.outer.store[name]
if ok {
for obj.Type() == REFERENCE { // for is in theory not needed as we deref new refs.
obj = obj.(Reference).Value()
if !ok {
e = e.outer
continue
}
for {
o, ok := obj.(Reference)
if !ok {
break
}
ref := Reference{Name: name, RefEnv: e.outer}
orig.store[name] = ref
orig.getMiss++ // creating a ref is a miss.
return &ref, true
obj = o.Value()
}
e = e.outer
ref := Reference{Name: name, RefEnv: e.outer}
orig.store[name] = ref
orig.getMiss++ // creating a ref is a miss.
return &ref, true
}
return nil, false
}
Expand Down

0 comments on commit 2a94511

Please sign in to comment.