Skip to content

Commit

Permalink
fix: user-friendly errors for undefined FunC functions (tact-lang#587)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gusarich authored Jul 21, 2024
1 parent 72665ba commit 92dd7fe
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Error messages for unicode code points outside of valid range: PR [#535](https://github.com/tact-lang/tact/pull/535)
- Correct regex for unicode code points and escaping of control codes in generated comments: PR [#535](https://github.com/tact-lang/tact/pull/535)
- Add `impure` specifier to some stdlib functions that are expected to throw errors: PR [#565](https://github.com/tact-lang/tact/pull/565)
- Defining non-existing native FunC functions now throws an understandable compilation error: PR [#585](https://github.com/tact-lang/tact/pull/585)

## [1.4.0] - 2024-06-21

Expand Down
10 changes: 10 additions & 0 deletions src/pipeline/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,16 @@ export async function build(args: {
logger,
});
if (!c.ok) {
const match = c.log.match(
/undefined function `([^`]+)`, defining a global function of unknown type/,
);
if (match) {
const message = `Function '${match[1]}' does not exist in imported FunC sources`;
logger.error(message);
errorMessages.push(new Error(message));
return { ok: false, error: errorMessages };
}

logger.error(c.log);
ok = false;
errorMessages.push(new Error(c.log));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@name(iDoNotExist)
native youDo();

contract Test {
get fun test() {
youDo();
}
}
14 changes: 14 additions & 0 deletions src/test/compilation-failed/func-errors.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { __DANGER_resetNodeId } from "../../grammar/ast";
import { itShouldNotCompile } from "./util";

describe("func-errors", () => {
beforeEach(() => {
__DANGER_resetNodeId();
});

itShouldNotCompile({
testName: "func-function-does-not-exist",
errorMessage:
"Function 'iDoNotExist' does not exist in imported FunC sources",
});
});
5 changes: 5 additions & 0 deletions src/test/compilation-failed/tact.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@
"name": "contract-duplicate-receiver-opcode",
"path": "./contracts/contract-duplicate-receiver-opcode.tact",
"output": "./contracts/output"
},
{
"name": "func-function-does-not-exist",
"path": "./contracts/func-function-does-not-exist.tact",
"output": "./contracts/output"
}
]
}

0 comments on commit 92dd7fe

Please sign in to comment.