tokiwa-software / fuzion

The Fuzion Language Implementation
https://fuzion-lang.dev
GNU General Public License v3.0
47 stars 11 forks source link

`option` (indirectly) inherits from `Sequence`: unexpected behavior #3797

Open maxteufel opened 1 month ago

maxteufel commented 1 month ago
$ cat ex_option.fz 
ex_option =>
  x option i32 := nil
  y String := x.as_string ""
  say y

$ fz ex_option.fz 

this works like if someone had intended to use x.get "", but it doesn't work for x.get "something else". this is because Sequence has as_string taking a separator argument.

we should reconsider having option (by means of switch) inherit from Sequence.

fridis commented 1 month ago

The behavior in your example is surprising, but I think you can run into a similar surprise call as_string on a Sequence, maybe we should rename as_string (one argument)? I very much like to be able to treat an option as a Sequence of length 0 or 1.