resolver: Always validate return statements
Previously we were only validating return statements that had values, which meant we were not catching issues when the return value was omitted in a non-void function. Fixed: chromium:1219037 Change-Id: If68f67a4a79e46894eee08322726000074c9095b Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/54561 Kokoro: Kokoro <noreply+kokoro@google.com> Commit-Queue: James Price <jrprice@google.com> Auto-Submit: James Price <jrprice@google.com> Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
parent
d80bb9d997
commit
7e22196a35
|
@ -200,6 +200,21 @@ TEST_F(ResolverFunctionValidationTest,
|
|||
"return type, returned 'i32', expected 'void'");
|
||||
}
|
||||
|
||||
TEST_F(ResolverFunctionValidationTest,
|
||||
FunctionTypeMustMatchReturnStatementTypeMissing_fail) {
|
||||
// fn func -> f32 { return; }
|
||||
Func("func", ast::VariableList{}, ty.f32(),
|
||||
ast::StatementList{
|
||||
Return(Source{Source::Location{12, 34}}, nullptr),
|
||||
},
|
||||
ast::DecorationList{});
|
||||
|
||||
EXPECT_FALSE(r()->Resolve());
|
||||
EXPECT_EQ(r()->error(),
|
||||
"12:34 error v-000y: return statement type must match its function "
|
||||
"return type, returned 'void', expected 'f32'");
|
||||
}
|
||||
|
||||
TEST_F(ResolverFunctionValidationTest,
|
||||
FunctionTypeMustMatchReturnStatementTypeF32_pass) {
|
||||
// fn func -> f32 { return 2.0; }
|
||||
|
|
|
@ -3189,13 +3189,14 @@ bool Resolver::Return(ast::ReturnStatement* ret) {
|
|||
|
||||
if (auto* value = ret->value()) {
|
||||
Mark(value);
|
||||
|
||||
// Validate after processing the return value expression so that its type
|
||||
// is available for validation
|
||||
return Expression(value) && ValidateReturn(ret);
|
||||
if (!Expression(value)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
// Validate after processing the return value expression so that its type is
|
||||
// available for validation.
|
||||
return ValidateReturn(ret);
|
||||
}
|
||||
|
||||
bool Resolver::ValidateSwitch(const ast::SwitchStatement* s) {
|
||||
|
|
Loading…
Reference in New Issue