Akuli / jou

Yet another programming language
MIT License
11 stars 4 forks source link

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

Open Akuli opened 6 months ago

Akuli commented 6 months ago

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 commented 6 months ago

Interesting use of -> for attributes.

Akuli commented 6 months ago

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 commented 6 months ago

I just interpreted it as accessing a class instances attribute.