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

Variable scoping is not documented #191

Open
anton-trunov opened this issue Apr 17, 2024 · 4 comments
Open

Variable scoping is not documented #191

anton-trunov opened this issue Apr 17, 2024 · 4 comments
Assignees
Labels
section: Book /book section of the docs: Guides, Cheatsheets, and a streamlined sequence of educational materials
Milestone

Comments

@anton-trunov
Copy link
Member

For instance, is variable shadowing allowed?

@novusnota novusnota added the section: Book /book section of the docs: Guides, Cheatsheets, and a streamlined sequence of educational materials label Apr 17, 2024
@novusnota
Copy link
Member

Shadowing is not allowed. And with recent fix of variable scoping bug in loops, the scope of a variable declared with let is one of the following curly-brace-enclosed syntaxes that most closely contains the let statement:

  • Function body
  • Any block statement inside the function body: try...catch, if...else, all loops, etc.

The scope of the persistent state variable is all the receiver, getter and internal function bodies of the contract/trait.

@anton-trunov
Copy link
Member Author

We need var-scope tests in the compiler to make sure the docs say the truth: tact-lang/tact#288

@novusnota
Copy link
Member

novusnota commented Apr 27, 2024

Intrestingly enough, function shadowing is not allowed, but has inconsistent behavior:

  • when trying to define a function from global.ts, say, ton() it works just fine, but when trying to call it the actual global.ts ton() is being called instead of the freshly defined one. Notice, that there's no error if the arguments are exactly what the global.ts function expected, which can lead to unexpected results!
  • but when one re-defines a library function, say, beginCell() — that very attempt is marked as an error Static function beginCell() already exists.

@anton-trunov
Copy link
Member Author

Shadowing is not allowed

We should definitely have test cases for all the cases listed below in #191 (comment)

@novusnota novusnota modified the milestone: v1.3.0 Apr 28, 2024
@novusnota novusnota added this to the v1.4.0 milestone May 22, 2024
@novusnota novusnota modified the milestones: v1.4.0, v1.5.0 Jun 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
section: Book /book section of the docs: Guides, Cheatsheets, and a streamlined sequence of educational materials
Projects
None yet
Development

No branches or pull requests

2 participants