fuzion icon indicating copy to clipboard operation
fuzion copied to clipboard

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

Open maxteufel opened this issue 1 year ago • 1 comments

$ 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.

maxteufel avatar Sep 17 '24 10:09 maxteufel

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.

fridis avatar Sep 17 '24 12:09 fridis

option no longer inherits from Sequence: #4734

maxteufel avatar Feb 11 '25 09:02 maxteufel