From c91f19f297942b8ed2c0f6df227567977d5ebc47 Mon Sep 17 00:00:00 2001 From: Gusarich Date: Sun, 26 May 2024 17:16:21 +0300 Subject: [PATCH 1/4] complete --- src/abi/map.ts | 16 ++--- src/generator/Writer.ts | 10 ++-- src/generator/createABI.ts | 2 +- src/generator/writeProgram.ts | 2 +- src/generator/writers/writeExpression.ts | 8 +-- src/generator/writers/writeFunction.ts | 2 +- src/grammar/checkConstAttributes.ts | 2 +- src/grammar/checkFunctionAttributes.ts | 2 +- src/imports/resolveImports.ts | 2 +- src/types/resolveABITypeRef.ts | 29 +++++---- src/types/resolveConstantValue.ts | 4 +- src/types/resolveDescriptors.ts | 75 +++++++++++++----------- src/types/resolveErrors.ts | 2 +- src/types/resolveExpression.ts | 9 ++- src/types/resolveStatements.ts | 34 +++++------ 15 files changed, 110 insertions(+), 89 deletions(-) diff --git a/src/abi/map.ts b/src/abi/map.ts index 4f0dc1527..147463a66 100644 --- a/src/abi/map.ts +++ b/src/abi/map.ts @@ -36,7 +36,7 @@ export const MapFunctions: Map = 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, ); } @@ -50,7 +50,7 @@ export const MapFunctions: Map = 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, ); } @@ -121,7 +121,7 @@ export const MapFunctions: Map = new Map([ } } else { throwError( - `${t.name} can't be value of a map`, + `"${t.name}" can't be value of a map`, ref, ); } @@ -170,7 +170,7 @@ export const MapFunctions: Map = new Map([ } } else { throwError( - `${t.name} can't be value of a map`, + `"${t.name}" can't be value of a map`, ref, ); } @@ -204,7 +204,7 @@ export const MapFunctions: Map = 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, ); } @@ -269,7 +269,7 @@ export const MapFunctions: Map = 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, ); } @@ -314,7 +314,7 @@ export const MapFunctions: Map = 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, ); } @@ -348,7 +348,7 @@ export const MapFunctions: Map = 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, ); } diff --git a/src/generator/Writer.ts b/src/generator/Writer.ts index 07a0b9138..f44827301 100644 --- a/src/generator/Writer.ts +++ b/src/generator/Writer.ts @@ -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 } // @@ -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; @@ -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); } diff --git a/src/generator/createABI.ts b/src/generator/createABI.ts index ff48304d2..1debd9ee6 100644 --- a/src/generator/createABI.ts +++ b/src/generator/createABI.ts @@ -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"); diff --git a/src/generator/writeProgram.ts b/src/generator/writeProgram.ts index 0402cc557..2bf88b2b4 100644 --- a/src/generator/writeProgram.ts +++ b/src/generator/writeProgram.ts @@ -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 diff --git a/src/generator/writers/writeExpression.ts b/src/generator/writers/writeExpression.ts index 55499590b..516cd4e59 100644 --- a/src/generator/writers/writeExpression.ts +++ b/src/generator/writers/writeExpression.ts @@ -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, ); } @@ -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, ); } @@ -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, ); } @@ -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, ); } diff --git a/src/generator/writers/writeFunction.ts b/src/generator/writers/writeFunction.ts index 1ced347f7..75c53577f 100644 --- a/src/generator/writers/writeFunction.ts +++ b/src/generator/writers/writeFunction.ts @@ -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)}) {`, diff --git a/src/grammar/checkConstAttributes.ts b/src/grammar/checkConstAttributes.ts index 9d5fdbbb3..641941d0b 100644 --- a/src/grammar/checkConstAttributes.ts +++ b/src/grammar/checkConstAttributes.ts @@ -8,7 +8,7 @@ export function checkConstAttributes( const k = new Set(); 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); } diff --git a/src/grammar/checkFunctionAttributes.ts b/src/grammar/checkFunctionAttributes.ts index f20b43bf6..57be7d027 100644 --- a/src/grammar/checkFunctionAttributes.ts +++ b/src/grammar/checkFunctionAttributes.ts @@ -8,7 +8,7 @@ export function checkFunctionAttributes( const k = new Set(); 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); } diff --git a/src/imports/resolveImports.ts b/src/imports/resolveImports.ts index 01056afe9..c83e52438 100644 --- a/src/imports/resolveImports.ts +++ b/src/imports/resolveImports.ts @@ -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 diff --git a/src/types/resolveABITypeRef.ts b/src/types/resolveABITypeRef.ts index 696cd74fd..869df0c4e 100644 --- a/src/types/resolveABITypeRef.ts +++ b/src/types/resolveABITypeRef.ts @@ -173,7 +173,7 @@ export function resolveABIType(src: ASTField): ABITypeRef { }; } if (src.type.name === "StringBuilder") { - throwError(`Unsupported type ${src.type.name}`, src.ref); + throwError(`Unsupported type "${src.type.name}"`, src.ref); } // @@ -232,7 +232,7 @@ export function resolveABIType(src: ASTField): ABITypeRef { ); } } else { - throwError(`Unsupported map key type ${src.type.key}`, src.ref); + throwError(`Unsupported map key type "${src.type.key}"`, src.ref); } // Resolve value type @@ -267,7 +267,10 @@ export function resolveABIType(src: ASTField): ABITypeRef { ); } } else if (src.type.value === "Slice") { - throwError(`Unsupported map value type ${src.type.value}`, src.ref); + throwError( + `Unsupported map value type "${src.type.value}"`, + src.ref, + ); } else if (src.type.value === "Address") { value = "address"; if (src.type.valueAs) { @@ -277,12 +280,18 @@ export function resolveABIType(src: ASTField): ABITypeRef { ); } } else if (src.type.value === "String") { - throwError(`Unsupported map value type ${src.type.value}`, src.ref); + throwError( + `Unsupported map value type "${src.type.value}"`, + src.ref, + ); } else if ( src.type.value === "StringBuilder" || src.type.value === "Builder" ) { - throwError(`Unsupported map value type ${src.type.value}`, src.ref); + throwError( + `Unsupported map value type "${src.type.value}"`, + src.ref, + ); } else { value = src.type.value; valueFormat = "ref"; @@ -333,7 +342,7 @@ export function createABITypeRefFromTypeRef( return { kind: "simple", type: "string", optional: src.optional }; } if (src.name === "StringBuilder") { - throw Error(`Unsupported type ${src.name}`); + throw Error(`Unsupported type "${src.name}"`); } // Structs @@ -366,7 +375,7 @@ export function createABITypeRefFromTypeRef( throwError(`Unsupported format ${src.keyAs} for map key`, ref); } } else { - throw Error(`Unsupported map key type ${src.key}`); + throw Error(`Unsupported map key type "${src.key}"`); } // Resolve value type @@ -401,7 +410,7 @@ export function createABITypeRefFromTypeRef( ); } } else if (src.value === "Slice") { - throw Error(`Unsupported map value type ${src.value}`); + throw Error(`Unsupported map value type "${src.value}"`); } else if (src.value === "Address") { value = "address"; if (src.valueAs) { @@ -411,9 +420,9 @@ export function createABITypeRefFromTypeRef( ); } } else if (src.value === "String") { - throw Error(`Unsupported map value type ${src.value}`); + throw Error(`Unsupported map value type "${src.value}"`); } else if (src.value === "StringBuilder" || src.value === "Builder") { - throw Error(`Unsupported map value type ${src.value}`); + throw Error(`Unsupported map value type "${src.value}"`); } else { value = src.value; valueFormat = "ref"; diff --git a/src/types/resolveConstantValue.ts b/src/types/resolveConstantValue.ts index 87a148626..298529352 100644 --- a/src/types/resolveConstantValue.ts +++ b/src/types/resolveConstantValue.ts @@ -185,7 +185,7 @@ export function resolveConstantValue( if (type.kind !== "ref") { throwError( - `Expected constant value, got ${printTypeRef(type)}`, + `Expected constant value, got "${printTypeRef(type)}"`, ast.ref, ); } @@ -222,5 +222,5 @@ export function resolveConstantValue( return reduceCell(ast); } - throwError(`Expected constant value, got ${printTypeRef(type)}`, ast.ref); + throwError(`Expected constant value, got "${printTypeRef(type)}"`, ast.ref); } diff --git a/src/types/resolveDescriptors.ts b/src/types/resolveDescriptors.ts index 1ef256c04..66b82a9ca 100644 --- a/src/types/resolveDescriptors.ts +++ b/src/types/resolveDescriptors.ts @@ -200,7 +200,7 @@ export function resolveDescriptors(ctx: CompilerContext) { for (const a of ast.types) { if (types.has(a.name)) { - throwError(`Type ${a.name} already exists`, a.ref); + throwError(`Type "${a.name}" already exists`, a.ref); } const uid = uidForName(a.name, types); @@ -347,14 +347,17 @@ export function resolveDescriptors(ctx: CompilerContext) { if ( types.get(a.name)!.fields.find((v) => v.name === f.name) ) { - throwError(`Field ${f.name} already exists`, f.ref); + throwError(`Field "${f.name}" already exists`, f.ref); } if ( types .get(a.name)! .constants.find((v) => v.name === f.name) ) { - throwError(`Constant ${f.name} already exists`, f.ref); + throwError( + `Constant "${f.name}" already exists`, + f.ref, + ); } types .get(a.name)! @@ -368,14 +371,17 @@ export function resolveDescriptors(ctx: CompilerContext) { if ( types.get(a.name)!.fields.find((v) => v.name === f.name) ) { - throwError(`Field ${f.name} already exists`, f.ref); + throwError(`Field "${f.name}" already exists`, f.ref); } if ( types .get(a.name)! .constants.find((v) => v.name === f.name) ) { - throwError(`Constant ${f.name} already exists`, f.ref); + throwError( + `Constant "${f.name}" already exists`, + f.ref, + ); } if (f.attributes.find((v) => v.type !== "overrides")) { throwError(`Constant can be only overridden`, f.ref); @@ -391,7 +397,7 @@ export function resolveDescriptors(ctx: CompilerContext) { if (a.kind === "def_struct") { for (const f of a.fields) { if (types.get(a.name)!.fields.find((v) => v.name === f.name)) { - throwError(`Field ${f.name} already exists`, f.ref); + throwError(`Field "${f.name}" already exists`, f.ref); } types .get(a.name)! @@ -404,7 +410,7 @@ export function resolveDescriptors(ctx: CompilerContext) { } if (a.fields.length === 0 && !a.message) { throwError( - `Struct ${a.name} must have at least one field`, + `Struct "${a.name}" must have at least one field`, a.ref, ); } @@ -417,7 +423,7 @@ export function resolveDescriptors(ctx: CompilerContext) { if ( types.get(a.name)!.fields.find((v) => v.name === f.name) ) { - throwError(`Field ${f.name} already exists`, f.ref); + throwError(`Field "${f.name}" already exists`, f.ref); } if (f.as) { throwError( @@ -437,14 +443,17 @@ export function resolveDescriptors(ctx: CompilerContext) { if ( types.get(a.name)!.fields.find((v) => v.name === f.name) ) { - throwError(`Field ${f.name} already exists`, f.ref); + throwError(`Field "${f.name}" already exists`, f.ref); } if ( types .get(a.name)! .constants.find((v) => v.name === f.name) ) { - throwError(`Constant ${f.name} already exists`, f.ref); + throwError( + `Constant "${f.name}" already exists`, + f.ref, + ); } if (f.attributes.find((v) => v.type === "overrides")) { throwError( @@ -765,7 +774,7 @@ export function resolveDescriptors(ctx: CompilerContext) { } if (s.functions.has(f.name)) { throwError( - `Function ${f.name} already exists in type ${s.name}`, + `Function "${f.name}" already exists in type "${s.name}"`, s.ast.ref, ); } @@ -912,7 +921,7 @@ export function resolveDescriptors(ctx: CompilerContext) { ) ) { throwError( - `Receive function for ${arg.type.name} already exists`, + `Receive function for "${arg.type.name}" already exists`, d.ref, ); } @@ -1055,7 +1064,7 @@ export function resolveDescriptors(ctx: CompilerContext) { ) ) { throwError( - `Bounce receive function for ${arg.type.name} already exists`, + `Bounce receive function for "${arg.type.name}" already exists`, d.ref, ); } @@ -1097,7 +1106,7 @@ export function resolveDescriptors(ctx: CompilerContext) { ) ) { throwError( - `Bounce receive function for ${t.name} already exists`, + `Bounce receive function for "${t.name}" already exists`, d.ref, ); } @@ -1213,7 +1222,7 @@ export function resolveDescriptors(ctx: CompilerContext) { const ex = t.fields.find((v) => v.name === f.name); if (!ex) { throwError( - `Trait ${tr.name} requires field ${f.name}`, + `Trait "${tr.name}" requires field "${f.name}"`, t.ast.ref, ); } @@ -1221,7 +1230,7 @@ export function resolveDescriptors(ctx: CompilerContext) { // Check type if (!typeRefEquals(f.type, ex.type)) { throwError( - `Trait ${tr.name} requires field ${f.name} of type ${printTypeRef(f.type)}`, + `Trait "${tr.name}" requires field "${f.name}" of type "${printTypeRef(f.type)}"`, t.ast.ref, ); } @@ -1240,7 +1249,7 @@ export function resolveDescriptors(ctx: CompilerContext) { const ex = t.functions.get(f.name); if (!ex && f.isAbstract) { throwError( - `Trait ${tr.name} requires function ${f.name}`, + `Trait "${tr.name}" requires function "${f.name}"`, t.ast.ref, ); } @@ -1249,25 +1258,25 @@ export function resolveDescriptors(ctx: CompilerContext) { if (ex && ex.isOverrides) { if (f.isGetter) { throwError( - `Overridden function ${f.name} can not be a getter`, + `Overridden function "${f.name}" can not be a getter`, ex.ast.ref, ); } if (f.isMutating !== ex.isMutating) { throwError( - `Overridden function ${f.name} should have same mutability`, + `Overridden function "${f.name}" should have same mutability`, ex.ast.ref, ); } if (!typeRefEquals(f.returns, ex.returns)) { throwError( - `Overridden function ${f.name} should have same return type`, + `Overridden function "${f.name}" should have same return type`, ex.ast.ref, ); } if (f.args.length !== ex.args.length) { throwError( - `Overridden function ${f.name} should have same number of arguments`, + `Overridden function "${f.name}" should have same number of arguments`, ex.ast.ref, ); } @@ -1276,7 +1285,7 @@ export function resolveDescriptors(ctx: CompilerContext) { const b = f.args[i]; if (!typeRefEquals(a.type, b.type)) { throwError( - `Overridden function ${f.name} should have same argument types`, + `Overridden function "${f.name}" should have same argument types`, ex.ast.ref, ); } @@ -1287,7 +1296,7 @@ export function resolveDescriptors(ctx: CompilerContext) { // Check duplicates if (ex) { throwError( - `Function ${f.name} already exist in ${t.name}`, + `Function "${f.name}" already exist in "${t.name}"`, t.ast.ref, ); } @@ -1308,7 +1317,7 @@ export function resolveDescriptors(ctx: CompilerContext) { f.ast.attributes.find((v) => v.type === "abstract") ) { throwError( - `Trait ${tr.name} requires constant ${f.name}`, + `Trait "${tr.name}" requires constant "${f.name}"`, t.ast.ref, ); } @@ -1320,7 +1329,7 @@ export function resolveDescriptors(ctx: CompilerContext) { ) { if (!typeRefEquals(f.type, ex.type)) { throwError( - `Overridden constant ${f.name} should have same type`, + `Overridden constant "${f.name}" should have same type`, ex.ast.ref, ); } @@ -1330,7 +1339,7 @@ export function resolveDescriptors(ctx: CompilerContext) { // Check duplicates if (ex) { throwError( - `Constant ${f.name} already exist in ${t.name}`, + `Constant "${f.name}" already exist in "${t.name}"`, t.ast.ref, ); } @@ -1430,7 +1439,7 @@ export function resolveDescriptors(ctx: CompilerContext) { } if (processing.has(name)) { throwError( - `Circular dependency detected for type ${name}`, + `Circular dependency detected for type "${name}"`, types.get(name)!.ast.ref, ); } @@ -1464,7 +1473,7 @@ export function resolveDescriptors(ctx: CompilerContext) { const handler = (src: ASTNode) => { if (src.kind === "init_of") { if (!types.has(src.name)) { - throwError(`Type ${src.name} not found`, src.ref); + throwError(`Type "${src.name}" not found`, src.ref); } dependsOn.add(src.name); } @@ -1520,7 +1529,7 @@ export function resolveDescriptors(ctx: CompilerContext) { if (r.self) { if (types.get(r.self)!.functions.has(r.name)) { throwError( - `Function ${r.name} already exists in type ${r.self}`, + `Function "${r.name}" already exists in type "${r.self}"`, r.ast.ref, ); } @@ -1528,12 +1537,12 @@ export function resolveDescriptors(ctx: CompilerContext) { } else { if (staticFunctions.has(r.name) || GlobalFunctions.has(r.name)) { throwError( - `Static function ${r.name} already exists`, + `Static function "${r.name}" already exists`, r.ast.ref, ); } if (staticConstants.has(r.name)) { - throwError(`Static constant ${r.name} already exists`, a.ref); + throwError(`Static constant "${r.name}" already exists`, a.ref); } staticFunctions.set(r.name, r); } @@ -1545,10 +1554,10 @@ export function resolveDescriptors(ctx: CompilerContext) { for (const a of ast.constants) { if (staticConstants.has(a.name)) { - throwError(`Static constant ${a.name} already exists`, a.ref); + throwError(`Static constant "${a.name}" already exists`, a.ref); } if (staticFunctions.has(a.name) || GlobalFunctions.has(a.name)) { - throwError(`Static function ${a.name} already exists`, a.ref); + throwError(`Static function "${a.name}" already exists`, a.ref); } staticConstants.set(a.name, buildConstantDescription(a)); } diff --git a/src/types/resolveErrors.ts b/src/types/resolveErrors.ts index f0f46c6df..bdd6c29fb 100644 --- a/src/types/resolveErrors.ts +++ b/src/types/resolveErrors.ts @@ -34,7 +34,7 @@ function resolveStringsInAST(ast: ASTNode, ctx: CompilerContext) { if ( Object.values(exceptions.all(ctx)).find((v) => v.id === id) ) { - throw new Error(`Duplicate error id: ${resolved}`); + throw new Error(`Duplicate error id: "${resolved}"`); } ctx = exceptions.set(ctx, resolved, { value: resolved, id }); } diff --git a/src/types/resolveExpression.ts b/src/types/resolveExpression.ts index 4bf502371..d2e28491a 100644 --- a/src/types/resolveExpression.ts +++ b/src/types/resolveExpression.ts @@ -131,7 +131,10 @@ function resolveStructNew( // Check existing const f = tp.fields.find((v) => v.name === e.name); if (!f) { - throwError(`Unknown fields "${e.name}" in type ${tp.name}`, e.ref); + throwError( + `Unknown fields "${e.name}" in type "${tp.name}"`, + e.ref, + ); } // Resolve expression @@ -141,7 +144,7 @@ function resolveStructNew( const expressionType = getExpType(ctx, e.exp); if (!isAssignable(expressionType, f.type)) { throwError( - `Invalid type "${printTypeRef(expressionType)}" for fields "${e.name}" with type ${printTypeRef(f.type)} in type ${tp.name}`, + `Invalid type "${printTypeRef(expressionType)}" for fields "${e.name}" with type "${printTypeRef(f.type)}" in type "${tp.name}"`, e.ref, ); } @@ -151,7 +154,7 @@ function resolveStructNew( for (const f of tp.fields) { if (f.default === undefined && !processed.has(f.name)) { throwError( - `Missing fields "${f.name}" in type ${tp.name}`, + `Missing fields "${f.name}" in type "${tp.name}"`, exp.ref, ); } diff --git a/src/types/resolveStatements.ts b/src/types/resolveStatements.ts index 5320ec61c..0f30da955 100644 --- a/src/types/resolveStatements.ts +++ b/src/types/resolveStatements.ts @@ -175,14 +175,14 @@ function processStatements( const variableType = resolveTypeRef(ctx, s.type); if (!isAssignable(expressionType, variableType)) { throwError( - `Type mismatch: ${printTypeRef(expressionType)} is not assignable to ${printTypeRef(variableType)}`, + `Type mismatch: "${printTypeRef(expressionType)}" is not assignable to "${printTypeRef(variableType)}"`, s.ref, ); } // Add variable to statement context if (sctx.vars.has(s.name)) { - throwError(`Variable already exists: ${s.name}`, s.ref); + throwError(`Variable already exists: "${s.name}"`, s.ref); } sctx = addVariable(s.name, variableType, sctx); } else if (s.kind === "statement_assign") { @@ -197,7 +197,7 @@ function processStatements( const tailType = getExpType(ctx, s.path[s.path.length - 1]); if (!isAssignable(expressionType, tailType)) { throwError( - `Type mismatch: ${printTypeRef(expressionType)} is not assignable to ${printTypeRef(tailType)}`, + `Type mismatch: "${printTypeRef(expressionType)}" is not assignable to "${printTypeRef(tailType)}"`, s.ref, ); } @@ -259,7 +259,7 @@ function processStatements( expressionType.optional ) { throwError( - `Type mismatch: ${printTypeRef(expressionType)} is not assignable to Bool`, + `Type mismatch: "${printTypeRef(expressionType)}" is not assignable to "Bool"`, s.ref, ); } @@ -272,14 +272,14 @@ function processStatements( const expressionType = getExpType(ctx, s.expression); if (!isAssignable(expressionType, sctx.returns)) { throwError( - `Type mismatch: ${printTypeRef(expressionType)} is not assignable to ${printTypeRef(sctx.returns)}`, + `Type mismatch: "${printTypeRef(expressionType)}" is not assignable to "${printTypeRef(sctx.returns)}"`, s.ref, ); } } else { if (sctx.returns.kind !== "void") { throwError( - `Type mismatch: void is not assignable to ${printTypeRef(sctx.returns)}`, + `Type mismatch: "void" is not assignable to "${printTypeRef(sctx.returns)}"`, s.ref, ); } @@ -289,12 +289,12 @@ function processStatements( if (sctx.requiredFields.length > 0) { if (sctx.requiredFields.length === 1) { throwError( - `Field ${sctx.requiredFields[0]} is not set`, + `Field "${sctx.requiredFields[0]}" is not set`, sctx.root, ); } else { throwError( - `Fields ${sctx.requiredFields.join(", ")} are not set`, + `Fields ${sctx.requiredFields.map((x) => '"' + x + '"').join(", ")} are not set`, sctx.root, ); } @@ -317,7 +317,7 @@ function processStatements( expressionType.optional ) { throwError( - `Type mismatch: ${printTypeRef(expressionType)} is not assignable to Int`, + `Type mismatch: "${printTypeRef(expressionType)}" is not assignable to "Int"`, s.ref, ); } @@ -340,7 +340,7 @@ function processStatements( expressionType.optional ) { throwError( - `Type mismatch: ${printTypeRef(expressionType)} is not assignable to bool`, + `Type mismatch: "${printTypeRef(expressionType)}" is not assignable to "Bool"`, s.ref, ); } @@ -363,7 +363,7 @@ function processStatements( expressionType.optional ) { throwError( - `Type mismatch: ${printTypeRef(expressionType)} is not assignable to bool`, + `Type mismatch: "${printTypeRef(expressionType)}" is not assignable to "Bool"`, s.ref, ); } @@ -383,7 +383,7 @@ function processStatements( // Process catchName variable for exit code if (initialCtx.vars.has(s.catchName)) { - throwError(`Variable already exists: ${s.catchName}`, s.ref); + throwError(`Variable already exists: "${s.catchName}"`, s.ref); } let catchCtx = addVariable( s.catchName, @@ -419,12 +419,12 @@ function processStatements( // Check if map is valid const mapVariable = sctx.vars.get(s.map.value); if (!mapVariable || mapVariable.kind !== "map") { - throwError(`Variable ${s.map.value} is not a map`, s.ref); + throwError(`Variable "${s.map.value}" is not a map`, s.ref); } // Add key and value to statement context if (initialCtx.vars.has(s.keyName)) { - throwError(`Variable already exists: ${s.keyName}`, s.ref); + throwError(`Variable already exists: "${s.keyName}"`, s.ref); } let foreachCtx = addVariable( s.keyName, @@ -432,7 +432,7 @@ function processStatements( initialCtx, ); if (foreachCtx.vars.has(s.valueName)) { - throwError(`Variable already exists: ${s.valueName}`, s.ref); + throwError(`Variable already exists: "${s.valueName}"`, s.ref); } foreachCtx = addVariable( s.valueName, @@ -484,12 +484,12 @@ function processFunctionBody( if (res.sctx.requiredFields.length > 0) { if (res.sctx.requiredFields.length === 1) { throwError( - `Field ${res.sctx.requiredFields[0]} is not set`, + `Field "${res.sctx.requiredFields[0]}" is not set`, res.sctx.root, ); } else { throwError( - `Fields ${res.sctx.requiredFields.join(", ")} are not set`, + `Fields ${res.sctx.requiredFields.map((x) => '"' + x + '"').join(", ")} are not set`, res.sctx.root, ); } From 6911ea72a86e779dff61c73e4871268e1bc8ea91 Mon Sep 17 00:00:00 2001 From: Gusarich Date: Sun, 26 May 2024 17:19:30 +0300 Subject: [PATCH 2/4] fix --- src/test/feature-implicit-init.spec.ts | 2 +- .../resolveDescriptors.spec.ts.snap | 24 +++++------ .../resolveStatements.spec.ts.snap | 40 +++++++++---------- 3 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/test/feature-implicit-init.spec.ts b/src/test/feature-implicit-init.spec.ts index 3632c03ed..157474679 100644 --- a/src/test/feature-implicit-init.spec.ts +++ b/src/test/feature-implicit-init.spec.ts @@ -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); }); diff --git a/src/types/__snapshots__/resolveDescriptors.spec.ts.snap b/src/types/__snapshots__/resolveDescriptors.spec.ts.snap index 45b1a3b21..ee38e2019 100644 --- a/src/types/__snapshots__/resolveDescriptors.spec.ts.snap +++ b/src/types/__snapshots__/resolveDescriptors.spec.ts.snap @@ -59,7 +59,7 @@ Line 8, col 17: `; exports[`resolveDescriptors should fail descriptors for case-6 1`] = ` -":11:3: Field b already exists +":11:3: Field "b" already exists Line 11, col 3: 10 | b: Int; > 11 | b: Int; @@ -69,7 +69,7 @@ Line 11, col 3: `; exports[`resolveDescriptors should fail descriptors for case-7 1`] = ` -":11:3: Field b already exists +":11:3: Field "b" already exists Line 11, col 3: 10 | b: Int; > 11 | b: Int; @@ -119,7 +119,7 @@ Line 12, col 23: `; exports[`resolveDescriptors should fail descriptors for case-12 1`] = ` -":12:1: Type Main already exists +":12:1: Type "Main" already exists Line 12, col 1: 11 | > 12 | struct Main { @@ -129,7 +129,7 @@ Line 12, col 1: `; exports[`resolveDescriptors should fail descriptors for case-13 1`] = ` -":12:1: Type Main already exists +":12:1: Type "Main" already exists Line 12, col 1: 11 | > 12 | struct Main { @@ -139,7 +139,7 @@ Line 12, col 1: `; exports[`resolveDescriptors should fail descriptors for case-14 1`] = ` -":12:1: Type Main already exists +":12:1: Type "Main" already exists Line 12, col 1: 11 | > 12 | contract Main { @@ -149,7 +149,7 @@ Line 12, col 1: `; exports[`resolveDescriptors should fail descriptors for case-15 1`] = ` -":12:1: Struct Main must have at least one field +":12:1: Struct "Main" must have at least one field Line 12, col 1: 11 | > 12 | struct Main { @@ -159,7 +159,7 @@ Line 12, col 1: `; exports[`resolveDescriptors should fail descriptors for case-16 1`] = ` -":16:1: Struct Main must have at least one field +":16:1: Struct "Main" must have at least one field Line 16, col 1: 15 | > 16 | struct Main { @@ -169,7 +169,7 @@ Line 16, col 1: `; exports[`resolveDescriptors should fail descriptors for case-17 1`] = ` -":8:1: Function hello already exists in type Main +":8:1: Function "hello" already exists in type "Main" Line 8, col 1: 7 | > 8 | contract Main { @@ -199,7 +199,7 @@ Line 13, col 5: `; exports[`resolveDescriptors should fail descriptors for case-20 1`] = ` -":12:1: Function hello already exists in type Main +":12:1: Function "hello" already exists in type "Main" Line 12, col 1: 11 | > 12 | extends fun hello(self: Main): Bool { @@ -219,7 +219,7 @@ Line 17, col 3: `; exports[`resolveDescriptors should fail descriptors for case-22 1`] = ` -":24:3: Bounce receive function for A already exists +":24:3: Bounce receive function for "A" already exists Line 24, col 3: 23 | > 24 | bounced(msg: bounced) { @@ -259,7 +259,7 @@ Line 8, col 21: `; exports[`resolveDescriptors should fail descriptors for case-26 1`] = ` -":1:1: Static function ton already exists +":1:1: Static function "ton" already exists Line 1, col 1: > 1 | fun ton() { ^~~~~~~~~~~ @@ -268,7 +268,7 @@ Line 1, col 1: `; exports[`resolveDescriptors should fail descriptors for case-27 1`] = ` -":1:1: Static function dumpStack already exists +":1:1: Static function "dumpStack" already exists Line 1, col 1: > 1 | fun dumpStack() { ^~~~~~~~~~~~~~~~~ diff --git a/src/types/__snapshots__/resolveStatements.spec.ts.snap b/src/types/__snapshots__/resolveStatements.spec.ts.snap index 5c6caf733..e9d62394c 100644 --- a/src/types/__snapshots__/resolveStatements.spec.ts.snap +++ b/src/types/__snapshots__/resolveStatements.spec.ts.snap @@ -1,7 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`resolveStatements should fail statements for case-0 1`] = ` -":9:5: Type mismatch: Int is not assignable to Bool +":9:5: Type mismatch: "Int" is not assignable to "Bool" Line 9, col 5: 8 | fun isZero(x: Int): Bool { > 9 | return x; @@ -11,7 +11,7 @@ Line 9, col 5: `; exports[`resolveStatements should fail statements for case-1 1`] = ` -":9:5: Type mismatch: Bool is not assignable to Int +":9:5: Type mismatch: "Bool" is not assignable to "Int" Line 9, col 5: 8 | fun isZero(x: Int): Bool { > 9 | repeat(true) { @@ -21,7 +21,7 @@ Line 9, col 5: `; exports[`resolveStatements should fail statements for case-2 1`] = ` -":9:5: Type mismatch: Int is not assignable to bool +":9:5: Type mismatch: "Int" is not assignable to "Bool" Line 9, col 5: 8 | fun isZero(x: Int): Bool { > 9 | while(x) { @@ -31,7 +31,7 @@ Line 9, col 5: `; exports[`resolveStatements should fail statements for case-3 1`] = ` -":9:5: Type mismatch: Int is not assignable to bool +":9:5: Type mismatch: "Int" is not assignable to "Bool" Line 9, col 5: 8 | fun isZero(x: Int): Bool { > 9 | do { @@ -41,7 +41,7 @@ Line 9, col 5: `; exports[`resolveStatements should fail statements for case-4 1`] = ` -":9:5: Type mismatch: Int is not assignable to Bool +":9:5: Type mismatch: "Int" is not assignable to "Bool" Line 9, col 5: 8 | fun isZero(x: Int): Bool { > 9 | if (x) { @@ -51,7 +51,7 @@ Line 9, col 5: `; exports[`resolveStatements should fail statements for case-5 1`] = ` -":9:5: Type mismatch: String is not assignable to Int +":9:5: Type mismatch: "String" is not assignable to "Int" Line 9, col 5: 8 | fun isZero(x: Int): Bool { > 9 | x = "hello world"; @@ -101,7 +101,7 @@ Line 20, col 27: `; exports[`resolveStatements should fail statements for case-10 1`] = ` -":10:5: Type mismatch: Int is not assignable to Bool +":10:5: Type mismatch: "Int" is not assignable to "Bool" Line 10, col 5: 9 | let a: Int = 0; > 10 | let b: Bool = 0; @@ -111,7 +111,7 @@ Line 10, col 5: `; exports[`resolveStatements should fail statements for case-11 1`] = ` -":17:9: Invalid type "Bool" for fields "b" with type Int in type SomeStruct +":17:9: Invalid type "Bool" for fields "b" with type "Int" in type "SomeStruct" Line 17, col 9: 16 | a: 1, > 17 | b: false // Invalid type @@ -131,7 +131,7 @@ Line 17, col 9: `; exports[`resolveStatements should fail statements for case-13 1`] = ` -":16:25: Missing fields "c" in type SomeStruct +":16:25: Missing fields "c" in type "SomeStruct" Line 16, col 25: 15 | fun main() { > 16 | let a: SomeStruct = SomeStruct{ @@ -151,7 +151,7 @@ Line 26, col 25: `; exports[`resolveStatements should fail statements for case-15 1`] = ` -":10:5: Field value is not set +":10:5: Field "value" is not set Line 10, col 5: 9 | value: Int; > 10 | init() { @@ -161,7 +161,7 @@ Line 10, col 5: `; exports[`resolveStatements should fail statements for case-16 1`] = ` -":10:5: Field value is not set +":10:5: Field "value" is not set Line 10, col 5: 9 | value: Int; > 10 | init(arg: Bool) { @@ -171,7 +171,7 @@ Line 10, col 5: `; exports[`resolveStatements should fail statements for case-17 1`] = ` -":10:5: Field value is not set +":10:5: Field "value" is not set Line 10, col 5: 9 | value: Int; > 10 | init(arg: Bool) { @@ -181,7 +181,7 @@ Line 10, col 5: `; exports[`resolveStatements should fail statements for case-18 1`] = ` -":10:5: Field value is not set +":10:5: Field "value" is not set Line 10, col 5: 9 | value: Int; > 10 | init(arg: Bool) { @@ -281,7 +281,7 @@ Line 5, col 43: `; exports[`resolveStatements should fail statements for case-28 1`] = ` -":5:5: Type mismatch: Bool is not assignable to Int +":5:5: Type mismatch: "Bool" is not assignable to "Int" Line 5, col 5: 4 | fun sample(): Int { > 5 | return (true ? true : false) ? true : false; @@ -341,7 +341,7 @@ Line 5, col 16: `; exports[`resolveStatements should fail statements for case-34 1`] = ` -":6:5: Variable already exists: e +":6:5: Variable already exists: "e" Line 6, col 5: 5 | let e: String = "qwe"; > 6 | try { @@ -351,7 +351,7 @@ Line 6, col 5: `; exports[`resolveStatements should fail statements for case-35 1`] = ` -":8:9: Type mismatch: Int is not assignable to String +":8:9: Type mismatch: "Int" is not assignable to "String" Line 8, col 9: 7 | } catch (e) { > 8 | return e; @@ -361,7 +361,7 @@ Line 8, col 9: `; exports[`resolveStatements should fail statements for case-36 1`] = ` -":14:26: Unknown fields "b" in type A +":14:26: Unknown fields "b" in type "A" Line 14, col 26: 13 | fun function() { > 14 | let D: A = A { x: a, b }; @@ -371,7 +371,7 @@ Line 14, col 26: `; exports[`resolveStatements should fail statements for case-37 1`] = ` -":6:5: Type mismatch: Bool is not assignable to +":6:5: Type mismatch: "Bool" is not assignable to "" Line 6, col 5: 5 | m.set(1, 2); > 6 | return m.del(1); @@ -471,7 +471,7 @@ Line 4, col 1: `; exports[`resolveStatements should fail statements for case-47 1`] = ` -":5:5: Variable already exists: k +":5:5: Variable already exists: "k" Line 5, col 5: 4 | let m: map = emptyMap(); > 5 | foreach (k, k in m) { @@ -481,7 +481,7 @@ Line 5, col 5: `; exports[`resolveStatements should fail statements for case-48 1`] = ` -":5:5: Variable already exists: m +":5:5: Variable already exists: "m" Line 5, col 5: 4 | let m: map = emptyMap(); > 5 | foreach (k, m in m) { From cd453f4bff05964acf50a311c84b5c3442ac46db Mon Sep 17 00:00:00 2001 From: Gusarich Date: Sun, 26 May 2024 17:21:53 +0300 Subject: [PATCH 3/4] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8181e86d0..483eb1544 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 From 09e595a929a62da7599f682502036f12e6ae3ff5 Mon Sep 17 00:00:00 2001 From: Daniil Sedov <42098239+Gusarich@users.noreply.github.com> Date: Mon, 27 May 2024 14:16:57 +0400 Subject: [PATCH 4/4] Update src/types/resolveStatements.ts Co-authored-by: Anton Trunov --- src/types/resolveStatements.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types/resolveStatements.ts b/src/types/resolveStatements.ts index 0f30da955..490551100 100644 --- a/src/types/resolveStatements.ts +++ b/src/types/resolveStatements.ts @@ -182,7 +182,7 @@ function processStatements( // Add variable to statement context if (sctx.vars.has(s.name)) { - throwError(`Variable already exists: "${s.name}"`, s.ref); + throwError(`Variable "${s.name}" already exists`, s.ref); } sctx = addVariable(s.name, variableType, sctx); } else if (s.kind === "statement_assign") {