Skip to content
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

fix #530: VM comparing file name with class name fails #538

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading