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

feat: update error message for reserved self function argument #1737

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 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 dev-docs/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
- Better error message for `extend function without parameters` error: PR [#1624](https://github.com/tact-lang/tact/pull/1624)
- Don't generate `lazy_deployment_completed` by default: PR [#1717](https://github.com/tact-lang/tact/pull/1717)
- Optimized `emptyCell()` and `emptySlice()` functions: PR [#1696](https://github.com/tact-lang/tact/pull/1696)
- Error message for reserved `self` function parameter now suggests using `extends` function modifier: PR [#1737](https://github.com/tact-lang/tact/pull/1737)

### Fixed

Expand Down
9 changes: 9 additions & 0 deletions src/types/__snapshots__/resolveDescriptors.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,15 @@ exports[`resolveDescriptors should fail descriptors for native-fun-getter 1`] =
"
`;

exports[`resolveDescriptors should fail descriptors for not-extend-function-self-param 1`] = `
"<unknown>:3:30: Parameter name "self" is reserved for functions with "extends" modifier
2 |
> 3 | asm(other self) fun testFunc(self: Int, other: Int) { 2 BLKDROP }
^~~~~~~~~
4 |
"
`;

exports[`resolveDescriptors should fail descriptors for override-for-non-existing-constant-in-contract-from-base-trait 1`] = `
"<unknown>:8:5: Constant "BAR" overrides nothing, remove "override" modifier or inherit any traits with this constant
7 | contract Test {
Expand Down
17 changes: 12 additions & 5 deletions src/types/resolveDescriptors.ts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will produce a confusing error message

extends fun foo(self: Int, self: String) { }

Parameter name "self" is reserved for functions with "extends" modifier

Here it is an extends function, it's just we have duplicate parameter names

Original file line number Diff line number Diff line change
Expand Up @@ -841,12 +841,19 @@ export function resolveDescriptors(ctx: CompilerContext, Ast: FactoryAst) {

// Check parameter names
const exNames: Set<string> = new Set();
for (const param of params) {
for (const [i, param] of params.entries()) {
if (isSelfId(param.name)) {
throwCompilationError(
'Parameter name "self" is reserved',
param.loc,
);
if (i === 0) {
throwCompilationError(
'Parameter name "self" is reserved for functions with "extends" modifier',
param.loc,
);
anton-trunov marked this conversation as resolved.
Show resolved Hide resolved
} else {
throwCompilationError(
'Parameter name "self" is reserved',
param.loc,
);
}
}
if (exNames.has(idText(param.name))) {
throwCompilationError(
Expand Down
3 changes: 3 additions & 0 deletions src/types/test-failed/not-extend-function-self-param.tact
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
primitive Int;

asm(other self) fun testFunc(self: Int, other: Int) { 2 BLKDROP }