diff --git a/spec/lang/operator/is_spec.lua b/spec/lang/operator/is_spec.lua index c771bfc1..84bd177f 100644 --- a/spec/lang/operator/is_spec.lua +++ b/spec/lang/operator/is_spec.lua @@ -9,6 +9,7 @@ describe("flow analysis with is", function() end ]], { { y = 1, msg = "unknown type b"}, + { y = 2, msg = "cannot resolve a type for x here"}, { y = 2, msg = "unknown variable: x"}, { y = 2, msg = "cannot resolve a type for x here"}, })) diff --git a/spec/lang/operator/or_spec.lua b/spec/lang/operator/or_spec.lua index 7282e8ad..6b6a2467 100644 --- a/spec/lang/operator/or_spec.lua +++ b/spec/lang/operator/or_spec.lua @@ -201,6 +201,19 @@ describe("or", function() end ]])) + it("resolves the negation of 'or' with '== nil' when 'if' returns (regression test for #823)", util.check([[ + local function foo(bar:string):boolean + if bar == nil or #bar == 0 then + return true + end + + print(bar:upper()) + return false + end + + foo("asdf") + ]])) + it("resolves the negation of 'or' when 'if' returns, error case with interface", util.check_type_error([[ local interface Type t: string diff --git a/tl.lua b/tl.lua index fdaae079..efcf95a9 100644 --- a/tl.lua +++ b/tl.lua @@ -10487,7 +10487,7 @@ a.types[i], b.types[i]), } elseif f.fact == "and" and f.f2 and f.f2.fact == "truthy" then return eval_not(self, f.f1) elseif f.fact == "or" and f.f2 and f.f2.fact == "truthy" then - return eval_fact(self, f.f1) + return eval_not(self, f.f1) elseif f.fact == "and" then return or_facts(self, eval_not(self, f.f1), eval_not(self, f.f2)) elseif f.fact == "or" then diff --git a/tl.tl b/tl.tl index ab3ce77d..1af48412 100644 --- a/tl.tl +++ b/tl.tl @@ -10487,7 +10487,7 @@ do elseif f is AndFact and f.f2 and f.f2.fact == "truthy" then return eval_not(self, f.f1) elseif f is OrFact and f.f2 and f.f2.fact == "truthy" then - return eval_fact(self, f.f1) + return eval_not(self, f.f1) elseif f is AndFact then return or_facts(self, eval_not(self, f.f1), eval_not(self, f.f2)) elseif f is OrFact then