Skip to content

Change the syntax for the not-Nil operator

Yorick Peterse requested to merge not-nil-operator into master

Inko has had the "*" prefix operator to inform the compiler that a certain type is not Nil. For example:

1| let x: ?Integer = 10
2|
3| *x

Here the compiler would know that on line 3 "x" is not Nil. The "*" prefix syntax is not natural, as it is used for dereferencing pointers in other languages. The internal name is equally confusing, but won't be changed for now.

This commit changes the syntax to a postfix "!", meaning you'd write the following instead:

1| let x: ?Integer = 10
2|
3| x!

This is a bit more common, is easier to parse, and makes more sense compared to the "*" prefix operator. This operator also works better in chaining, as you no longer need to group expressions:

a!.b!.c!

Instead of:

(*a).(*b).(*c)

Merge request reports