compiler: don't crash on a, b := int(0)
Fixes https://gcc.gnu.org/PR101851
Change-Id: I15d372bc4919f84156151993aa2fe5cfa3d8afae
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/341330
Trust: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
diff --git a/go/expressions.cc b/go/expressions.cc
index f462b0e..67917da 100644
--- a/go/expressions.cc
+++ b/go/expressions.cc
@@ -11202,12 +11202,23 @@
{
Location loc = this->location();
+ if (this->is_error_expression())
+ return Expression::make_error(loc);
+
// A type cast can look like a function call.
if (this->fn_->is_type_expression()
&& this->args_ != NULL
&& this->args_->size() == 1)
- return Expression::make_cast(this->fn_->type(), this->args_->front(),
- loc);
+ {
+ if (this->expected_result_count_ != 0
+ && this->expected_result_count_ != 1)
+ {
+ this->report_error(_("type conversion result count mismatch"));
+ return Expression::make_error(loc);
+ }
+ return Expression::make_cast(this->fn_->type(), this->args_->front(),
+ loc);
+ }
// Because do_type will return an error type and thus prevent future
// errors, check for that case now to ensure that the error gets