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

sometimes error message for using . in class is misleading #479

Open
Akuli opened this issue Dec 25, 2023 · 3 comments
Open

sometimes error message for using . in class is misleading #479

Akuli opened this issue Dec 25, 2023 · 3 comments

Comments

@Akuli
Copy link
Owner

Akuli commented Dec 25, 2023

I had something like this:

class EquationSolver:
    substitution_history: Substitution*
    substitution_history_len: int

    def substitute(self, sub: Substitution) -> None:
        self->substitution_history[self.substitution_history_len++] = sub

Note that last line should have self-> in two places, but the second one is self. instead. The error message I got was:

compiler error in file "part2.jou", line 140: cannot increment a field of self

This is a bad error message, because fields of self can be incremented, you just need to do it using the -> operator instead of the . operator.

@Moosems
Copy link

Moosems commented Dec 29, 2023

Interesting use of -> for attributes.

@Akuli
Copy link
Owner Author

Akuli commented Dec 30, 2023

Jou's -> is just like in C: foo->bar is equivalent to (*foo).bar, so you use it when foo is a pointer to an instance of a class.

I should document classes :)

@Moosems
Copy link

Moosems commented Dec 30, 2023

I just interpreted it as accessing a class instances attribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants