degory / ghul

compiler for the ghūl programming language
https://ghul.dev
GNU Affero General Public License v3.0
4 stars 0 forks source link

Don't require `new` in constructor expressions #1141

Closed degory closed 6 months ago

degory commented 6 months ago

Currently, constructor expressions require the new keyword. The main reason for this is that we can't parse generic type expressions in a value expression context, so new is needed to explicitly tell the parser to expect a type expression.

It would be good to support construction without needing new. new is often associated with OOP object construction, but some of the values new constructs in ghūl are not objects (e.g., structs, union variants). While new does highlight that construction is special compared to a regular method call, you could argue that (...) already signals an arbitrary amount of work could happen, including object construction and side effects: new on top of (...) doesn't add any further information.

Once we have a solution for #883 we will be able to recognize constructor expressions without needing them to be preceded by new

To support bootstrapping and until ghul-test and the runtime library are updated to remove use of new, we will need to support constructor expressions with and without new.

let l = Collections.LIST[int]();