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

Forbid shadowing static functions from global.ts #351

Merged
merged 3 commits into from
May 24, 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 @@ -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() {

}
Loading