Skip to content

Commit

Permalink
fix: forbid shadowing builtin static functions (tact-lang#351)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gusarich authored May 24, 2024
1 parent 3816c7e commit 9915bd1
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- `log2` and `log` math functions were adjusted for consistency in error throwing: PR [#342](https://github.com/tact-lang/tact/pull/342)
- 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)

Expand Down
18 changes: 18 additions & 0 deletions src/types/__snapshots__/resolveDescriptors.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,24 @@ Line 8, col 21:
"
`;
exports[`resolveDescriptors should fail descriptors for case-26 1`] = `
"<unknown>:1:1: Static function ton already exists
Line 1, col 1:
> 1 | fun ton() {
^~~~~~~~~~~
2 |
"
`;
exports[`resolveDescriptors should fail descriptors for case-27 1`] = `
"<unknown>:1:1: Static function dumpStack already exists
Line 1, col 1:
> 1 | fun dumpStack() {
^~~~~~~~~~~~~~~~~
2 |
"
`;
exports[`resolveDescriptors should resolve descriptors for case-0 1`] = `
{
"BaseTrait": {
Expand Down
5 changes: 3 additions & 2 deletions src/types/resolveDescriptors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { resolveABIType } from "./resolveABITypeRef";
import { Address, Cell } from "@ton/core";
import { enabledExternals } from "../config/features";
import { isRuntimeType } from "./isRuntimeType";
import { GlobalFunctions } from "../abi/global";

const store = createContextStore<TypeDescription>();
const staticFunctionsStore = createContextStore<FunctionDescription>();
Expand Down Expand Up @@ -1525,7 +1526,7 @@ export function resolveDescriptors(ctx: CompilerContext) {
}
types.get(r.self)!.functions.set(r.name, r);
} else {
if (staticFunctions.has(r.name)) {
if (staticFunctions.has(r.name) || GlobalFunctions.has(r.name)) {
throwError(
`Static function ${r.name} already exists`,
r.ast.ref,
Expand All @@ -1546,7 +1547,7 @@ export function resolveDescriptors(ctx: CompilerContext) {
if (staticConstants.has(a.name)) {
throwError(`Static constant ${a.name} already exists`, a.ref);
}
if (staticFunctions.has(a.name)) {
if (staticFunctions.has(a.name) || GlobalFunctions.has(a.name)) {
throwError(`Static function ${a.name} already exists`, a.ref);
}
staticConstants.set(a.name, buildConstantDescription(a));
Expand Down
3 changes: 3 additions & 0 deletions src/types/test-failed/case-26.tact
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fun ton() {

}
3 changes: 3 additions & 0 deletions src/types/test-failed/case-27.tact
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fun dumpStack() {

}

0 comments on commit 9915bd1

Please sign in to comment.