flofriday / Moose

🐐 A new fun programming language
MIT License
6 stars 1 forks source link

Methods mixed with operator fail in the typechecker #27

Closed flofriday closed 1 year ago

flofriday commented 1 year ago

Example

image

Note

You have to ignore the three lines before the error, its just some debug output.

Also the error highlighting is kinda messed up which shouldn't happen.

Jozott00 commented 1 year ago

The problem lies in the parser... it parses 2.(toString() + " two") instead of (2.toString()) + " two"

Jozott00 commented 1 year ago

Ok I solved the problem. The current precendence was determined at the wrong place, so it wasn't right. Fix was a oneliner.

Now we get the following typechecker error:


  1| print(2.toString() + " two")
           ^^^^^^^^^^

Function calls are only valid for identifiers, not for `2.toString`

@flofriday we probably should disable this type check for identifiers right? I don't even know why it says for identifier only since A().call() for example is valid...

flofriday commented 1 year ago

True, yes disable that. A couple of weeks I moved that check from the parser to the typechecket (and made it more lax) but I don't think it should be there at all.

Jozott00 commented 1 year ago

Actually this constraint is true, in the above example, the parsing predendence was still wrong, since it parsed the dereference before the call. The constraint just says that it is only possible to call a function by a name. This wouldn't be the case if we would have higher order function, but right now this holds true.