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

Class constants #510

Merged
merged 3 commits into from
Jan 18, 2022
Merged

Class constants #510

merged 3 commits into from
Jan 18, 2022

Conversation

Jason2605
Copy link
Member

Well detailed description of the change :

This PR adds the ability to define a constant within a class. This comes with the runtime guarantee that the value will not be changed.

E.g

class SomeClass {
    const classVariable = 10; // This will be shared among all "SomeClass" instances

    init() {
        this.x = 10; // "x" is set on the instance
    }
}

print(SomeClass.classVariable); // 10

const x = SomeClass();
const y = SomeClass();

print(x.classVariable); // 10
print(y.classVariable); // 10

SomeClass.classVaraible = 100; // Cannot assign to class constant 'SomeClass.classVariable'.

Resolves: #

#508

Type of change:

  • New feature

Housekeeping

  • Tests have been updated to reflect the changes done within this PR (if applicable).

  • Documentation has been updated to reflect the changes done within this PR (if applicable).

@Jason2605 Jason2605 added the enhancement Implementation of a new feature label Jan 17, 2022
@Jason2605 Jason2605 self-assigned this Jan 17, 2022
@briandowns
Copy link
Contributor

This looks awesome!

@Jason2605 Jason2605 linked an issue Jan 18, 2022 that may be closed by this pull request
1 task
@Jason2605
Copy link
Member Author

Thanks @briandowns!

I was on the fence about this due to the fact that it only provides runtime guarantees (const in a variable(I know that doesn't quite make sense, but hopefully you get what I mean) are detected at compile time).

Probably still worthwhile however

@Jason2605 Jason2605 merged commit cc133d3 into develop Jan 18, 2022
@Jason2605 Jason2605 deleted the feature/class_consts branch January 18, 2022 22:35
@Jason2605 Jason2605 mentioned this pull request Mar 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Implementation of a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] - Allow for the use of constants in classes
2 participants