Ticket #73 (closed defect: fixed)

Opened 7 months ago

Last modified 7 months ago

eval/loadString can use bogus environments

Reported by: JarrettBillingsley Assigned to: JarrettBillingsley
Priority: major Milestone: MiniD 2
Component: Stdlib Keywords:
Cc:

Description

This is an interesting effect of tailcalls. If you write a function like:

function foo()
{
    local val = eval("...something...")
    return val
}

This will evaluate the string within the global environment of foo(), as expected.

However:

function foo()
{
    return eval("...something...")
}

Same effect, right? Wrong. Since eval is tailcalled, the interpreter loses the information about what environment to use. foo's stack frame is overwritten by eval's. So it ends up using the environment of the function that called foo (and if foo itself was tailcalled, the environment of the function that called it, and if that was tailcalled... etc.). In other words, you don't know what environment it'll be evaluated in unless you're careful about how you call it.

In order to ameliorate this, it will be changed so that eval/loadString use the global namespace by default, and you'll be able to pass a namespace to use explicitly.

Change History

05/03/08 00:13:46 changed by JarrettBillingsley

This same issue is having icky effects on my attempt to implement isset(). Same deal. "function f() = isset("x")" will not use f's environment. Hrm.

05/03/08 00:15:56 changed by JarrettBillingsley

  • status changed from new to closed.
  • resolution set to fixed.

(In [302]) Closes #73, but the isSet issue remains.