source-academy/js-slang

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

Opened this issue · 2 comments

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

  • Source 1 to 4, Native variant

Affected Modules

  • All 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 source-academy/frontend#2419 (comment))

Workarounds

  • For now, when using Source 1-4 Native, you will have to ensure the imports share the same program block as the actual code
  • As for assessments, it will need to be manually imported by the students or given as part of the placeholder template.

This issue persists as of today.

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.