diff options
| -rw-r--r-- | CHANGES.md | 1 | ||||
| -rw-r--r-- | src/compile/optionals.c | 4 | ||||
| -rw-r--r-- | test/optionals.tm | 20 |
3 files changed, 23 insertions, 2 deletions
@@ -53,6 +53,7 @@ up resources, which can result in file handles being freed up. - `&` references failed to propagate when accessing fields like `foo.baz.method()` when `foo` is a `&Foo` and `baz.method()` takes a `&Baz`. + - Optional paths no longer fail to compile when you check them for `none`. ## v0.3 diff --git a/src/compile/optionals.c b/src/compile/optionals.c index b4930d02..ffe16248 100644 --- a/src/compile/optionals.c +++ b/src/compile/optionals.c @@ -92,8 +92,8 @@ Text_t check_none(type_t *t, Text_t value) { // NOTE: these use statement expressions ({...;}) because some compilers // complain about excessive parens around equality comparisons if (t->tag == PointerType || t->tag == FunctionType || t->tag == CStringType) return Texts("(", value, " == NULL)"); - else if (t == PATH_TYPE) return Texts("((", value, ").type.$tag == PATHTYPE_NONE)"); - else if (t == PATH_TYPE_TYPE) return Texts("((", value, ").$tag == PATHTYPE_NONE)"); + else if (t == PATH_TYPE) return Texts("((", value, ").type == PATHTYPE_NONE)"); + else if (t == PATH_TYPE_TYPE) return Texts("((", value, ") == PATHTYPE_NONE)"); else if (t->tag == BigIntType) return Texts("((", value, ").small == 0)"); else if (t->tag == ClosureType) return Texts("((", value, ").fn == NULL)"); else if (t->tag == NumType) diff --git a/test/optionals.tm b/test/optionals.tm index 51a78380..d26a9d46 100644 --- a/test/optionals.tm +++ b/test/optionals.tm @@ -61,6 +61,12 @@ func maybe_c_string(should_i:Bool->CString?) else return none +func maybe_path(should_i:Bool->Path?) + if should_i + return (./foo) + else + return none + func main() optional : Int? = 5 assert optional == 5 @@ -214,6 +220,20 @@ func main() fail("Truthy: $nope") else say("Falsey: $nope") + do + say("...") + say("Paths:") + yep := maybe_path(yes) + assert yep == (./foo) + nope := maybe_path(no) + assert nope == none + >> if yep + assert yep == (./foo) + else fail("Falsey: $yep") + >> if nope + fail("Truthy: $nope") + else say("Falsey: $nope") + if yep := maybe_int(yes) assert yep == 123 else fail("Unreachable") |
