Download
48 lines 766 BTextModified 2022-09-27 raw
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
union Foo {
    x,y:Int
    str:String

    Hello := Foo.str("Hello")

    def self.Derp()
        say "Derp $self"

    def Blorp()
        say "Blorp"
}

def show(foo:Foo)
    say "$foo: .x=$(foo.x) .y=$(foo.y) .str=$(foo.str)"
    if x := foo.x
        say "It was an x: $x"
    elseif y := foo.y
        say "It was a y: $y"
    elseif str := foo.str
        say "It was a str: $str"

def doop()
    tmp := Foo.str("hi")
    show(Foo.x(5))
    show(Foo.y(6))
    show(Foo.str("Hello"))

    f := Foo.Hello
    say "$f"
    f.Derp()
    Foo.Blorp()

doop()

union InnerUnion{
    int:Int,
    num:Num,
}

struct Struct {
    inner:InnerUnion,
}

foo := Struct{.inner = InnerUnion.int(5)}
say "$foo"
fail unless foo.inner.int == 5
fail unless foo.inner.num == nil