Skip to content

Commit

Permalink
fix #530: VM comparing file name with class name fails
Browse files Browse the repository at this point in the history
add function fileBasenameNoExtension to vm.ts
let validateFile compare class name to fileBasenameNoExtension
  • Loading branch information
Dorian Ignee committed Dec 20, 2024
1 parent a7d4db6 commit f658d9b
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion simulator/src/vm/vm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,24 @@ export class Vm {
}
}

private static fileBasenameNoExtension(file: string): string {
// Files that are part of the web-ide are usually passed with folders but without extensions.
// e.g.: /projects/08/FibonacciElement/Sys
if (file.includes("/")) {
file = file.split("/").pop() ?? "";
}

// Local files on Windows are usually passed with extension.
// e.g.: Sys.vm
if (file.includes(".")) {
file = file.split(".")[0];
}

return file;

// TODO: Check if this also works for Linux and MacOS
}

private static validateFile(file: ParsedVmFile) {
for (const inst of file.instructions) {
if (inst.op == "function") {
Expand All @@ -159,7 +177,7 @@ export class Vm {
),
);
}
if (parts[0] != file.name) {
if (parts[0] != this.fileBasenameNoExtension(file.name)) {
return Err(
createError(
`File name ${file.name} doesn't match class name ${parts[0]} (at ${inst.name})`,
Expand Down

0 comments on commit f658d9b

Please sign in to comment.