mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-21 18:59:21 +00:00
Make case selectors an integer value
Change-Id: I819983701ed6cca4eba1a05b4edc5fdff10fa88d Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22542 Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
committed by
dan sinclair
parent
e009c2058d
commit
579d33c528
@@ -1856,13 +1856,19 @@ ast::CaseSelectorList ParserImpl::case_selectors() {
|
||||
ast::CaseSelectorList selectors;
|
||||
|
||||
for (;;) {
|
||||
auto t = peek();
|
||||
auto cond = const_literal();
|
||||
if (has_error())
|
||||
return {};
|
||||
if (cond == nullptr)
|
||||
break;
|
||||
if (!cond->IsInt()) {
|
||||
set_error(t, "invalid case selector must be an integer value");
|
||||
return {};
|
||||
}
|
||||
|
||||
selectors.push_back(std::move(cond));
|
||||
std::unique_ptr<ast::IntLiteral> selector(cond.release()->AsInt());
|
||||
selectors.push_back(std::move(selector));
|
||||
}
|
||||
|
||||
return selectors;
|
||||
|
||||
@@ -41,6 +41,14 @@ TEST_F(ParserImplTest, SwitchBody_Case_InvalidConstLiteral) {
|
||||
EXPECT_EQ(p->error(), "1:6: unable to parse case selectors");
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, SwitchBody_Case_InvalidSelector_bool) {
|
||||
auto* p = parser("case true: { a = 4; }");
|
||||
auto e = p->switch_body();
|
||||
ASSERT_TRUE(p->has_error());
|
||||
ASSERT_EQ(e, nullptr);
|
||||
EXPECT_EQ(p->error(), "1:6: invalid case selector must be an integer value");
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, SwitchBody_Case_MissingConstLiteral) {
|
||||
auto* p = parser("case: { a = 4; }");
|
||||
auto e = p->switch_body();
|
||||
|
||||
Reference in New Issue
Block a user