mirror of
https://github.com/luau-lang/luau.git
synced 2024-11-15 14:25:44 +08:00
d00e93c82c
Fixes: https://github.com/Roblox/luau/issues/913 This PR adds support for type refinements around guard clauses that use `break` and `continue` statements inside a loop, similar to how guard clauses with `return` is supported. I had some free time today, so I figure I'd give a shot at a naïve fix for this at the very least. --- ## Resulting Change: Luau now supports type refinements within loops where a `continue` or `break` guard clause was used. For example: ```lua for _, object in objects :: {{value: string?}} do if not object.value then continue end local x: string = object.value -- OK; Used to emit "Type 'string?' could not be converted into 'string'" end ``` --------- Co-authored-by: Alexander McCord <amccord@roblox.com>
37 lines
688 B
C++
37 lines
688 B
C++
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
|
|
#pragma once
|
|
|
|
#include <memory>
|
|
|
|
namespace Luau
|
|
{
|
|
|
|
struct Scope;
|
|
using ScopePtr = std::shared_ptr<Scope>;
|
|
|
|
enum class ControlFlow
|
|
{
|
|
None = 0b00001,
|
|
Returns = 0b00010,
|
|
Throws = 0b00100,
|
|
Breaks = 0b01000,
|
|
Continues = 0b10000,
|
|
};
|
|
|
|
inline ControlFlow operator&(ControlFlow a, ControlFlow b)
|
|
{
|
|
return ControlFlow(int(a) & int(b));
|
|
}
|
|
|
|
inline ControlFlow operator|(ControlFlow a, ControlFlow b)
|
|
{
|
|
return ControlFlow(int(a) | int(b));
|
|
}
|
|
|
|
inline bool matches(ControlFlow a, ControlFlow b)
|
|
{
|
|
return (a & b) != ControlFlow(0);
|
|
}
|
|
|
|
} // namespace Luau
|