Skip to content

Commit

Permalink
update the variable not declared error message
Browse files Browse the repository at this point in the history
The scope now checks if the missing variable name
is present in a built-in module, and if it is, updates the
error message to tell the user that the identifier can be imported
from said built-in module
  • Loading branch information
JeanJPNM committed Dec 3, 2023
1 parent bd3e537 commit 188d39b
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions compiler/src/Scope.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { StoreValue } from "./values";
import { LiteralValue, StoreValue } from "./values";
import { AddressResolver } from "./instructions";
import {
IFunctionValue,
Expand Down Expand Up @@ -95,7 +95,16 @@ export class Scope implements IScope {
const value = this.data[identifier];
if (value) return value as INamedValue;
if (this.parent) return this.parent.get(identifier);
throw new CompilerError(`${identifier} is not declared.`);
let message = `${identifier} is not declared.`;

const name = new LiteralValue(identifier);
for (const moduleName in this.builtInModules) {
const module = this.builtInModules[moduleName];
if (module.hasProperty(this, name)) {
message += ` Did you mean to use "${identifier}" exported from "${moduleName}"?`;
}
}
throw new CompilerError(message);
}

set<T extends IValue>(name: string, value: T): T {
Expand Down

0 comments on commit 188d39b

Please sign in to comment.