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

Native: Importing new names in the REPL do not work properly #1495

Open sayomaki opened 1 year ago

sayomaki commented 1 year ago

EDIT: Imports in prelude and in main editor have been resolved as of #1625.

The issue left is importing new names in the REPL, refer to the same example below for a reproduction of the issue.

Here is the original issue:


When importing module functions and not using it directly (in the current program), this will lead to them being undeclared, i.e. using it in another program sharing the same context will lead to an error with name being undeclared.

However, this is not an issue/the case with the default source versions.

This causes issues when trying to execute module functions under REPL in different cells, or in the case of assessments, any module functions imported in the prepend chunk will not be declared and imported properly in the student's running program. (see examples below)

Affected Chapters & Variants

Affected Modules

Reproduction

1. Playground

Run these 2 chunks of code in separate cells (in the REPL), and you will see that the only the first cell works correctly.

import { noise_sound } from "sound";
noise_sound(2);

noise_sound(2); // doesn't work
Screenshot 2023-10-17 at 6 05 21 PM

2. Assessment

Create any assessment with prepend importing a module, then set the interpreter variant to native. You will see that the imported module functions do not work in the assessment. (see https://github.com/source-academy/frontend/issues/2419#issuecomment-1763694711)

Workarounds

martin-henz commented 7 months ago

This issue persists as of today.

sayomaki commented 7 months ago

The issue where imports do not carry over in assessment prelude and from the main code editor (on the left in playground) has been resolved in #1625, however importing new names in REPL issue still persists.

The issue title and post has been updated accordingly to reflect the updated issue.