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

Add quotes to all identifiers in error messages for consistency #363

Merged
merged 4 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Shadowing built-in static functions is now forbidden: PR [#351](https://github.com/tact-lang/tact/pull/351)
- Augmented assignment now throws compilation error for non-integer types: PR [#356](https://github.com/tact-lang/tact/pull/356)
- Built-in function `address()` now handles parse errors correctly: PR [#357](https://github.com/tact-lang/tact/pull/357)
- All identifiers in error messages are now quoted for consistency: PR [#363](https://github.com/tact-lang/tact/pull/363)

## [1.3.0] - 2024-05-03

Expand Down
16 changes: 8 additions & 8 deletions src/abi/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const MapFunctions: Map<string, AbiFunction> = new Map([
}
if (args[1].name !== self.key) {
throwError(
`set expects a ${self.key} as first argument`,
`set expects a "${self.key}" as first argument`,
ref,
);
}
Expand All @@ -50,7 +50,7 @@ export const MapFunctions: Map<string, AbiFunction> = new Map([
}
if (args[2].kind !== "null" && args[2].name !== self.value) {
throwError(
`set expects a ${self.value} as second argument`,
`set expects a "${self.value}" as second argument`,
ref,
);
}
Expand Down Expand Up @@ -121,7 +121,7 @@ export const MapFunctions: Map<string, AbiFunction> = new Map([
}
} else {
throwError(
`${t.name} can't be value of a map`,
`"${t.name}" can't be value of a map`,
ref,
);
}
Expand Down Expand Up @@ -170,7 +170,7 @@ export const MapFunctions: Map<string, AbiFunction> = new Map([
}
} else {
throwError(
`${t.name} can't be value of a map`,
`"${t.name}" can't be value of a map`,
ref,
);
}
Expand Down Expand Up @@ -204,7 +204,7 @@ export const MapFunctions: Map<string, AbiFunction> = new Map([
}
if (args[1].name !== self.key) {
throwError(
`set expects a ${self.key} as first argument`,
`set expects a "${self.key}" as first argument`,
ref,
);
}
Expand Down Expand Up @@ -269,7 +269,7 @@ export const MapFunctions: Map<string, AbiFunction> = new Map([
return `${ops.readerOpt(t.name, ctx)}(__tact_dict_get_${kind}_cell(${resolved[0]}, ${bits}, ${resolved[1]}))`;
} else {
throwError(
`${t.name} can't be value of a map`,
`"${t.name}" can't be value of a map`,
ref,
);
}
Expand Down Expand Up @@ -314,7 +314,7 @@ export const MapFunctions: Map<string, AbiFunction> = new Map([
return `${ops.readerOpt(t.name, ctx)}(__tact_dict_get_slice_cell(${resolved[0]}, 267, ${resolved[1]}))`;
} else {
throwError(
`${t.name} can't be value of a map`,
`"${t.name}" can't be value of a map`,
ref,
);
}
Expand Down Expand Up @@ -348,7 +348,7 @@ export const MapFunctions: Map<string, AbiFunction> = new Map([
}
if (args[1].name !== self.key) {
throwError(
`del expects a ${self.key} as first argument`,
`del expects a "${self.key}" as first argument`,
ref,
);
}
Expand Down
10 changes: 5 additions & 5 deletions src/generator/Writer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,10 @@ export class WriterContext {
//

if (this.#functions.has(name)) {
throw new Error(`Function ${name} already defined`); // Should not happen
throw new Error(`Function "${name}" already defined`); // Should not happen
}
if (this.#functionsRendering.has(name)) {
throw new Error(`Function ${name} already rendering`); // Should not happen
throw new Error(`Function "${name}" already rendering`); // Should not happen
}

//
Expand Down Expand Up @@ -189,10 +189,10 @@ export class WriterContext {
const comment = this.#pendingComment;
const context = this.#pendingContext;
if (!signature && name !== "$main") {
throw new Error(`Function ${name} signature not set`);
throw new Error(`Function "${name}" signature not set`);
}
if (!code) {
throw new Error(`Function ${name} body not set`);
throw new Error(`Function "${name}" body not set`);
}
this.#pendingDepends = null;
this.#pendingWriter = null;
Expand Down Expand Up @@ -319,7 +319,7 @@ export class WriterContext {

markRendered(key: string) {
if (this.#rendered.has(key)) {
throw new Error(`Key ${key} already rendered`);
throw new Error(`Key "${key}" already rendered`);
}
this.#rendered.add(key);
}
Expand Down
2 changes: 1 addition & 1 deletion src/generator/createABI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function createABI(ctx: CompilerContext, name: string): ContractABI {
// Contract
const contract = allTypes.find((v) => v.name === name)!;
if (!contract) {
throw Error(`Contract ${name} not found`);
throw Error(`Contract "${name}" not found`);
}
if (contract.kind !== "contract") {
throw Error("Not a contract");
Expand Down
2 changes: 1 addition & 1 deletion src/generator/writeProgram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ function writeAll(
const contracts = allTypes.filter((v) => v.kind === "contract");
const c = contracts.find((v) => v.name === name);
if (!c) {
throw Error(`Contract ${name} not found`);
throw Error(`Contract "${name}" not found`);
}

// Stdlib
Expand Down
8 changes: 4 additions & 4 deletions src/generator/writers/writeExpression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ export function writeExpression(f: ASTExpression, ctx: WriterContext): string {
((src.kind !== "ref" || src.optional) && src.kind !== "ref_bounced")
) {
throwError(
`Cannot access field of non-struct type: ${printTypeRef(src)}`,
`Cannot access field of non-struct type: "${printTypeRef(src)}"`,
f.ref,
);
}
Expand Down Expand Up @@ -609,7 +609,7 @@ export function writeExpression(f: ASTExpression, ctx: WriterContext): string {
const src = getExpType(ctx.ctx, f.src);
if (src === null) {
throwError(
`Cannot call function of non - direct type: ${printTypeRef(src)} `,
`Cannot call function of non - direct type: "${printTypeRef(src)}"`,
f.ref,
);
}
Expand All @@ -618,7 +618,7 @@ export function writeExpression(f: ASTExpression, ctx: WriterContext): string {
if (src.kind === "ref") {
if (src.optional) {
throwError(
`Cannot call function of non - direct type: ${printTypeRef(src)} `,
`Cannot call function of non - direct type: "${printTypeRef(src)}"`,
f.ref,
);
}
Expand Down Expand Up @@ -704,7 +704,7 @@ export function writeExpression(f: ASTExpression, ctx: WriterContext): string {
}

throwError(
`Cannot call function of non - direct type: ${printTypeRef(src)} `,
`Cannot call function of non - direct type: "${printTypeRef(src)}"`,
f.ref,
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/generator/writers/writeFunction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ export function writeGetter(f: FunctionDescription, ctx: WriterContext) {
// Render tensors
const self = f.self ? getType(ctx.ctx, f.self) : null;
if (!self) {
throw new Error(`No self type for getter ${f.name}`); // Impossible
throw new Error(`No self type for getter "${f.name}"`); // Impossible
}
ctx.append(
`_ %${f.name}(${f.args.map((v) => resolveFuncTupledType(v.type, ctx) + " " + id("$" + v.name)).join(", ")}) method_id(${getMethodId(f.name)}) {`,
Expand Down
2 changes: 1 addition & 1 deletion src/grammar/checkConstAttributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export function checkConstAttributes(
const k = new Set<string>();
for (const a of attributes) {
if (k.has(a.type)) {
throwError(`Duplicate function attribute ${a.type}`, a.ref);
throwError(`Duplicate function attribute "${a.type}"`, a.ref);
}
k.add(a.type);
}
Expand Down
2 changes: 1 addition & 1 deletion src/grammar/checkFunctionAttributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export function checkFunctionAttributes(
const k = new Set<string>();
for (const a of attrs) {
if (k.has(a.type)) {
throwError(`Duplicate function attribute ${a.type}`, a.ref);
throwError(`Duplicate function attribute "${a.type}"`, a.ref);
}
k.add(a.type);
}
Expand Down
2 changes: 1 addition & 1 deletion src/imports/resolveImports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function resolveImports(args: {
stdlib: args.stdlib,
});
if (!resolved.ok) {
throw new Error(`Could not resolve import ${i} in ${path}`);
throw new Error(`Could not resolve import "${i}" in ${path}`);
}

// Check if already imported
Expand Down
2 changes: 1 addition & 1 deletion src/test/feature-implicit-init.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe("feature-send", () => {
projectNames: ["implicit-init-2"],
});
expect((consoleLogger.error as jest.Mock).mock.lastCall[0]).toContain(
"Field test_field is not set",
'Field "test_field" is not set',
);
expect(result).toBe(false);
});
Expand Down
24 changes: 12 additions & 12 deletions src/types/__snapshots__/resolveDescriptors.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Line 8, col 17:
`;

exports[`resolveDescriptors should fail descriptors for case-6 1`] = `
"<unknown>:11:3: Field b already exists
"<unknown>:11:3: Field "b" already exists
Line 11, col 3:
10 | b: Int;
> 11 | b: Int;
Expand All @@ -69,7 +69,7 @@ Line 11, col 3:
`;

exports[`resolveDescriptors should fail descriptors for case-7 1`] = `
"<unknown>:11:3: Field b already exists
"<unknown>:11:3: Field "b" already exists
Line 11, col 3:
10 | b: Int;
> 11 | b: Int;
Expand Down Expand Up @@ -119,7 +119,7 @@ Line 12, col 23:
`;

exports[`resolveDescriptors should fail descriptors for case-12 1`] = `
"<unknown>:12:1: Type Main already exists
"<unknown>:12:1: Type "Main" already exists
Line 12, col 1:
11 |
> 12 | struct Main {
Expand All @@ -129,7 +129,7 @@ Line 12, col 1:
`;

exports[`resolveDescriptors should fail descriptors for case-13 1`] = `
"<unknown>:12:1: Type Main already exists
"<unknown>:12:1: Type "Main" already exists
Line 12, col 1:
11 |
> 12 | struct Main {
Expand All @@ -139,7 +139,7 @@ Line 12, col 1:
`;

exports[`resolveDescriptors should fail descriptors for case-14 1`] = `
"<unknown>:12:1: Type Main already exists
"<unknown>:12:1: Type "Main" already exists
Line 12, col 1:
11 |
> 12 | contract Main {
Expand All @@ -149,7 +149,7 @@ Line 12, col 1:
`;

exports[`resolveDescriptors should fail descriptors for case-15 1`] = `
"<unknown>:12:1: Struct Main must have at least one field
"<unknown>:12:1: Struct "Main" must have at least one field
Line 12, col 1:
11 |
> 12 | struct Main {
Expand All @@ -159,7 +159,7 @@ Line 12, col 1:
`;

exports[`resolveDescriptors should fail descriptors for case-16 1`] = `
"<unknown>:16:1: Struct Main must have at least one field
"<unknown>:16:1: Struct "Main" must have at least one field
Line 16, col 1:
15 |
> 16 | struct Main {
Expand All @@ -169,7 +169,7 @@ Line 16, col 1:
`;

exports[`resolveDescriptors should fail descriptors for case-17 1`] = `
"<unknown>:8:1: Function hello already exists in type Main
"<unknown>:8:1: Function "hello" already exists in type "Main"
Line 8, col 1:
7 |
> 8 | contract Main {
Expand Down Expand Up @@ -199,7 +199,7 @@ Line 13, col 5:
`;

exports[`resolveDescriptors should fail descriptors for case-20 1`] = `
"<unknown>:12:1: Function hello already exists in type Main
"<unknown>:12:1: Function "hello" already exists in type "Main"
Line 12, col 1:
11 |
> 12 | extends fun hello(self: Main): Bool {
Expand All @@ -219,7 +219,7 @@ Line 17, col 3:
`;

exports[`resolveDescriptors should fail descriptors for case-22 1`] = `
"<unknown>:24:3: Bounce receive function for A already exists
"<unknown>:24:3: Bounce receive function for "A" already exists
Line 24, col 3:
23 |
> 24 | bounced(msg: bounced<A>) {
Expand Down Expand Up @@ -259,7 +259,7 @@ Line 8, col 21:
`;

exports[`resolveDescriptors should fail descriptors for case-26 1`] = `
"<unknown>:1:1: Static function ton already exists
"<unknown>:1:1: Static function "ton" already exists
Line 1, col 1:
> 1 | fun ton() {
^~~~~~~~~~~
Expand All @@ -268,7 +268,7 @@ Line 1, col 1:
`;

exports[`resolveDescriptors should fail descriptors for case-27 1`] = `
"<unknown>:1:1: Static function dumpStack already exists
"<unknown>:1:1: Static function "dumpStack" already exists
Line 1, col 1:
> 1 | fun dumpStack() {
^~~~~~~~~~~~~~~~~
Expand Down
Loading
Loading