source-academy / js-slang

Implementations of sublanguages of JavaScript, TypeScript, Scheme and Python
https://source-academy.github.io/source/
Apache License 2.0
70 stars 104 forks source link

Source 3 native lost imported functions when switching context from prepend to student's code #1500

Closed larrywang0701 closed 7 months ago

larrywang0701 commented 1 year ago

https://github.com/source-academy/frontend/issues/2419

In Source 3 Native, the import executed in the prepend for an assessment can NOT keep in student's code. You have to re-import the functions again in student's code or use another constant to hold the imported value in the prepend.

larrywang0701 commented 1 year ago

Video

Originally posted by @martin-henz in https://github.com/source-academy/frontend/issues/2419#issuecomment-1763694711

sayomaki commented 1 year ago

I've actually already triaged and lodged an issue in #1495, and it has more details on the bug.

martin-henz commented 7 months ago

@sayomaki : the two issues may be related but describe different symptoms: One is talking about blocks the other one about the REPL.

sayomaki commented 7 months ago

@sayomaki : the two issues may be related but describe different symptoms: One is talking about blocks the other one about the REPL.

They are actually related, in the sense that the context is not preserved (since Source Native runs the code in native javascript), and as such the imported variables seems to be lost when executing (more) code. I will take a look again at this issue and see if it is possible to come up with a fix.