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

Add support for "constant" keyword in tuples #13

Open
cgcardona opened this issue Aug 23, 2019 · 7 comments
Open

Add support for "constant" keyword in tuples #13

cgcardona opened this issue Aug 23, 2019 · 7 comments
Labels
cashc-compiler Relates to the cashc compiler good first issue Good for newcomers

Comments

@cgcardona
Copy link
Contributor

cgcardona commented Aug 23, 2019

Currently defining a variable is

<Typ> name = expression;

This can be non-obvious to developers who are used to keywords before declaring variables. Also in CashScript variables can be reassigned.

For that reason this ticket is to add support for let and const. Their functionality would be inline with other mainstream languages.

let would be for variables which can be reassigned.

const would be for variables which have a constant value.

Both would be block scoped.

@rkalis rkalis added the cashc-compiler Relates to the cashc compiler label Sep 17, 2019
@rkalis
Copy link
Member

rkalis commented Sep 20, 2019

Right now I don't really want to add type inference to the language, as I think the time could be better spent on other things. So I don't want to add a let keyword, but I'm open to reconsidering that in the future. I think adding a keyword for constant values could be useful though.

@rkalis rkalis changed the title Add support for variable and constant keywords Add support for "constant" keyword Dec 13, 2019
@rkalis
Copy link
Member

rkalis commented Dec 13, 2019

Solidity uses the constant keyword in Solidity to indicate that a variable can't be changed (Source). This can be added to CashScript as well. Shouldn't change anything about the compiler output, but instead it should throw an error in semantic analysis when a constant variable is reassigned.

@rkalis
Copy link
Member

rkalis commented Jun 13, 2022

I just realised that we probably should add this modifier for tuple assignment as well. What do you think @nathanielCherian?

@nathanielCherian
Copy link
Contributor

For sure. I think we should wait until the modifier refactoring in #125 is merged, but it shouldn't be a tricky fix.

@mr-zwets
Copy link
Member

mr-zwets commented Sep 23, 2024

so the constant keyword was added in the v0.7.0 release

currently tuples don't allow for reassignments, so for now the support for the constant keyword there is less important.
I think we can close this old issue and create a more specific issue if there is/are still issues with the current keyword

@rkalis
Copy link
Member

rkalis commented Sep 23, 2024

@mr-zwets I think variables assigned through tuple assignment can be reassigned. e.g.

bytes x, bytes y = 0x1234.split(1);
x = 0x5678;

@mr-zwets
Copy link
Member

mr-zwets commented Sep 23, 2024

ah right, I misremember the open issue on 'Can't redefine variables in tuples' #136

I'll just rename this current issue on the 'constant' keyword so it reflects the current state of things

@mr-zwets mr-zwets changed the title Add support for "constant" keyword Add support for "constant" keyword in tuples Sep 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cashc-compiler Relates to the cashc compiler good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

4 participants