Improve binary expression validation error message

Example:
```
  var a : i32;
  var b : f32;
  if (a == b) {
    return vec4<f32>(0.4, 0.4, 0.8, 1.0);
  }
```

Outputs:
```
error: test7.wgsl:6:9 error: Binary expression operand types are invalid for this operation: i32 equal f32
  if (a == b) {
        ^^
```

Bug: tint:663
Change-Id: Idd2bb5a248b3c7d652483931d7dd58d5123e9ee8
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46640
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
Antonio Maiorano
2021-04-01 19:40:37 +00:00
committed by Commit Bot service account
parent 15c6ed048c
commit f1b643ee70
3 changed files with 33 additions and 41 deletions

View File

@@ -1174,7 +1174,10 @@ bool Resolver::ValidateBinary(ast::BinaryExpression* expr) {
}
diagnostics_.add_error(
"Binary expression operand types are invalid for this operation",
"Binary expression operand types are invalid for this operation: " +
lhs_type->FriendlyName(builder_->Symbols()) + " " +
FriendlyName(expr->op()) + " " +
rhs_type->FriendlyName(builder_->Symbols()),
expr->source());
return false;
}

View File

@@ -1270,7 +1270,10 @@ TEST_P(Expr_Binary_Test_Invalid, All) {
ASSERT_FALSE(r()->Resolve()) << r()->error();
ASSERT_EQ(r()->error(),
"12:34 error: Binary expression operand types are invalid for "
"this operation");
"this operation: " +
lhs_type->FriendlyName(Symbols()) + " " +
FriendlyName(expr->op()) + " " +
rhs_type->FriendlyName(Symbols()));
}
INSTANTIATE_TEST_SUITE_P(
ResolverTest,