Akuli / jou

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

Improve ensure_can_take_address #337

Closed Akuli closed 1 year ago

Akuli commented 1 year ago

The purpose of ensure_can_take_address() is to check that making a pointer to something (as in &foo) makes sense. But unlike you would expect, it isn't used just in the &foo syntax. Several other things, such as foo = bar and &foo.bar, also need a pointer to foo. The ensure_can_take_address() function handles them all.

This means that it is important for ensure_can_take_address() to generate good error messages. The error message logic is also a bit complicated, and previously behaved wrong in some corner cases: Foo{}.x++ resulted in an error message saying you are trying to increment a newly created instance. It now says that you are trying to increment a field of a newly created instance.