[torque] forbid brace-free if-else

Bug: v8:8012 v8:7793
Change-Id: Idc5d685d021fd107974b4415f7b855397004cb53
Reviewed-on: https://chromium-review.googlesource.com/1160841
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54893}
This commit is contained in:
Tobias Tebbi 2018-08-02 17:10:24 +02:00 committed by Commit Bot
parent 842569eb4b
commit 9991b626e4
2 changed files with 14 additions and 5 deletions

View File

@ -456,6 +456,13 @@ base::Optional<ParseResult> MakeIfStatement(
auto condition = child_results->NextAs<Expression*>(); auto condition = child_results->NextAs<Expression*>();
auto if_true = child_results->NextAs<Statement*>(); auto if_true = child_results->NextAs<Statement*>();
auto if_false = child_results->NextAs<base::Optional<Statement*>>(); auto if_false = child_results->NextAs<base::Optional<Statement*>>();
if (if_false && !(BlockStatement::DynamicCast(if_true) &&
(BlockStatement::DynamicCast(*if_false) ||
IfStatement::DynamicCast(*if_false)))) {
ReportError("if-else statements require curly braces");
}
Statement* result = Statement* result =
MakeNode<IfStatement>(is_constexpr, condition, if_true, if_false); MakeNode<IfStatement>(is_constexpr, condition, if_true, if_false);
return ParseResult{result}; return ParseResult{result};

View File

@ -98,10 +98,11 @@ module test {
} }
macro LabelTestHelper4(flag: constexpr bool): never labels Label4, Label5 { macro LabelTestHelper4(flag: constexpr bool): never labels Label4, Label5 {
if if constexpr(flag) {
constexpr(flag) goto Label4; goto Label4;
else } else {
goto Label5; goto Label5;
}
} }
macro CallLabelTestHelper4(flag: constexpr bool): bool { macro CallLabelTestHelper4(flag: constexpr bool): bool {
@ -120,10 +121,11 @@ module test {
let r1: bool = CallLabelTestHelper4(true); let r1: bool = CallLabelTestHelper4(true);
let r2: bool = CallLabelTestHelper4(false); let r2: bool = CallLabelTestHelper4(false);
if (r1 && !r2) if (r1 && !r2) {
return True; return True;
else } else {
return False; return False;
}
} }
macro GenericMacroTest<T : type>(param: T): Object { macro GenericMacroTest<T : type>(param: T): Object {