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

Rule 6.1.9: never use the name of a variable in the custom getter or setter #428

Closed
orchestr7 opened this issue Oct 19, 2020 · 0 comments · Fixed by #434
Closed

Rule 6.1.9: never use the name of a variable in the custom getter or setter #428

orchestr7 opened this issue Oct 19, 2020 · 0 comments · Fixed by #434
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@orchestr7
Copy link
Member

Rule 6.1.9: never use the name of a variable in the custom getter or setter

Even if you have ignored recommendation 6.1.8 you should be careful with using the name of the property in your custom getter/setter
as it can accidentally cause a recursive call and a StackOverflow Error. Use field keyword instead.

Very bad example:

    var isEmpty: Boolean
        set(value) {
            println("Side effect")
            isEmpty = value
        }
        get() = isEmpty
@orchestr7 orchestr7 added the enhancement New feature or request label Oct 19, 2020
@kentr0w kentr0w mentioned this issue Oct 20, 2020
6 tasks
@petertrr petertrr added this to the Chapter 6 milestone Oct 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants