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

Support Nullable`1[T] with the has-value operator #1127

Closed degory closed 7 months ago

degory commented 8 months ago

The ? (has value) operator should work with System.Nullable`1[T] and any other value that provides a has_value field or property.

For example given

some_thing[T](value: T) -> THING[T] => new THING[T](value);
none_thing[T]() -> THING[T] => new THING[T]();

struct THING[T] is
    value: T;
    has_value: bool;

    init(value: T) is
        has_value = true;
        self.value = value;
    si

    init() is
    si

    to_string() -> string => 
        if self? then
            "some THING {value}"
        else
            "none THING"
        fi;   
si

The following should be supported:

  let some = some_thing(42);
  let none = none_thing`[int]();    

  write_line(some?); // print True
  write_line(none?); // print False
degory commented 7 months ago

Fixed by #1129