Skip to content

Commit

Permalink
Allow common supertype if only one side is nil
Browse files Browse the repository at this point in the history
  • Loading branch information
aardappel committed Oct 18, 2023
1 parent b7522d2 commit cc9e20d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions dev/TODO.txt
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
- A debugging mode where a breakpoint can be set when the programming is already running?
Would be expensive to have a breakpoint check between every statement..
But this would enable traditional step by step debugging.
- tracepoint: like breakpoint, but automatic continue and the UI stays live.. for debugging values changing over time.

- Inline structs, further improvements:
- These were immutable in the past, because values were shared by pointer, but now there
Expand Down
7 changes: 5 additions & 2 deletions dev/src/lobster/typecheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,10 @@ struct TypeChecker {
if (et->t == V_UNDEFINED) goto error;
return st.Wrap(et, V_VECTOR, err ? &err->line : nullptr);
}
if (at->t == V_NIL && bt->t == V_NIL) {
auto et = Union(at->Element(), bt->Element(), aname, bname, CF_NONE, nullptr);
if (at->t == V_NIL || bt->t == V_NIL) {
at = at->ElementIfNil();
bt = bt->ElementIfNil();
auto et = Union(at, bt, aname, bname, CF_NONE, nullptr);
if (et->t == V_UNDEFINED) goto error;
return st.Wrap(et, V_NIL, err ? &err->line : nullptr);
}
Expand Down Expand Up @@ -3763,6 +3765,7 @@ bool Switch::Terminal(TypeChecker &tc) const {
if (cas->pattern->children.empty()) have_default = true;
if (!cas->cbody->Terminal(tc)) return false;
}
// FIXME: this should return true if the switch is proven exhaustive for types, sadly cannot guarantee that with enums.
return have_default;
}

Expand Down

0 comments on commit cc9e20d

Please sign in to comment.