-
-
Notifications
You must be signed in to change notification settings - Fork 402
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
var
of different scopes overriding each other's values
#1663
Comments
I've dug into the code and the spec and it turned out to be more complicated than I initially thought it would be. The cause of the issue is that boa currently doesn't create mutable/immutable bindings until it executes the variable declaration statements (for the sake of comprehensiveness, the substitution to the variable in the wrong scope is executed here). The spec requires the implementations to create the bindings before the execution of the function body, as specified in the abstract operation The fix seems not much, but naive fixes would break REPL, as there's nowhere for it to create bindings. Node.js addresses this problem by parsing every input in its REPL as a Script, whose bindings are created before the ScriptBody execution in the abstract operation I'm interested in fixing this, but it could take several PRs. To avoid temporary REPL breaks, I suppose changing the way REPL works first and then fully implementing |
Ah completely missed it, thanks for the info 👍 |
I think I just ran into this issue as well. For example, this TypeScript code: export function balance(request: BalanceRequest): Query<BalanceResponse> {
const aid = getUserAID(request.user);
const balance = state.balances[aid];
if (balance === undefined) {
return {
ok: 0
};
}
return {
ok: balance
};
}
export function claim(): Update<boolean> {
const callerAddress = addressFromPrincipal(ic.caller);
const balance = state.balances[callerAddress] ?? 0;
state.balances[callerAddress] = balance + 100000000;
const supply = state.supply;
state.supply = supply + 100000000;
return true;
} Compiles into this code which I am running in boa: function balance(request) {
var aid = getUserAID(request.user);
var balance = state.balances[aid];
if (balance === undefined) {
return {
ok: 0
};
}
return {
ok: balance
};
}
exports.balance = balance;
function claim() {
var _a;
var callerAddress = addressFromPrincipal(ic.caller);
var balance = (_a = state.balances[callerAddress]) !== null && _a !== void 0 ? _a : 0;
state.balances[callerAddress] = balance + 100000000;
var supply = state.supply;
state.supply = supply + 100000000;
return true;
}
exports.claim = claim; When I try to call the I assume my issue will be addressed here, just adding these examples for more information. |
This should be fixed via #1829. I tested the example in the this issue and it works as expected. |
One question here @raskad do we still need the "hoisting" hack we use to re-order statements? |
Do you mean this "hoisting"?
This is currently only relevant for function declarations. I'd have to take a closer look. There may be some other things that depend on this. |
So far this is working for me FYI |
Sounds good! Yea I was mentioning that :) it's a hack I had to introduce in the early days to make it work properly, but I would love to remove it as soon as it's possible. It reduces the parsing speed, and it's not really spec compliant. Also, when printing the AST or the original code, the order is not maintained. |
Describe the bug
It seems that there is a problem with the scoping of
var
in boa. In particular, assigning tovar
with the same name in different scopes will result in them overriding each other's values.This issue was discovered because the conformance test
built-ins/Object/fromEntries/evaluation-order.js
is failing.To Reproduce
Check out the following minimal example:
As mentioned above, another example of this issue is in the
built-ins/Object/fromEntries/evaluation-order.js
conformance test.Expected behavior
For the given minimal example, the expected output for both
console.log
s should be2
.Build environment (please complete the following information):
Additional notes
This bug occurs in both strict and non-strict mode.
The text was updated successfully, but these errors were encountered: