compiler: avoid knock-on errors from invalid interfaces

The test case for this is issue11614.go.

Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/278192
This commit is contained in:
Ian Lance Taylor 2020-12-14 22:50:18 -08:00
parent 8a5b8fc719
commit 788d204885
3 changed files with 37 additions and 9 deletions

View file

@ -1,4 +1,4 @@
85c390ec75c6c3f3fbfe08f6dac58585588c6211
10d3dd939d4cea7f40b76f8ff82c16aa12c01188
The first line of this file holds the git revision number of the last
merge done from the gofrontend repository.

View file

@ -174,7 +174,13 @@ Expression::export_name(Export_function_body* efb, const Named_object* no)
void
Expression::unused_value_error()
{
this->report_error(_("value computed is not used"));
if (this->type()->is_error())
{
go_assert(saw_errors());
this->set_is_error();
}
else
this->report_error(_("value computed is not used"));
}
// Note that this expression is an error. This is called by children
@ -888,8 +894,7 @@ Type_expression : public Expression
{ }
void
do_check_types(Gogo*)
{ this->report_error(_("invalid use of type")); }
do_check_types(Gogo*);
Expression*
do_copy()
@ -906,6 +911,18 @@ Type_expression : public Expression
Type* type_;
};
void
Type_expression::do_check_types(Gogo*)
{
if (this->type_->is_error())
{
go_assert(saw_errors());
this->set_is_error();
}
else
this->report_error(_("invalid use of type"));
}
void
Type_expression::do_dump_expression(Ast_dump_context* ast_dump_context) const
{

View file

@ -8984,8 +8984,11 @@ Interface_type::finalize_methods()
else if (this->find_method(p->name()) == NULL)
this->all_methods_->push_back(*p);
else
go_error_at(p->location(), "duplicate method %qs",
Gogo::message_name(p->name()).c_str());
{
go_error_at(p->location(), "duplicate method %qs",
Gogo::message_name(p->name()).c_str());
this->set_is_error();
}
}
std::vector<Named_type*> seen;
@ -9001,7 +9004,10 @@ Interface_type::finalize_methods()
if (it == NULL)
{
if (!t->is_error())
go_error_at(tl, "interface contains embedded non-interface");
{
go_error_at(tl, "interface contains embedded non-interface");
this->set_is_error();
}
continue;
}
if (it == this)
@ -9009,6 +9015,7 @@ Interface_type::finalize_methods()
if (!issued_recursive_error)
{
go_error_at(tl, "invalid recursive interface");
this->set_is_error();
issued_recursive_error = true;
}
continue;
@ -9027,6 +9034,7 @@ Interface_type::finalize_methods()
if (*q == nt)
{
go_error_at(tl, "inherited interface loop");
this->set_is_error();
break;
}
}
@ -9049,8 +9057,11 @@ Interface_type::finalize_methods()
q->type(), tl));
else if (!Type::are_identical(q->type(), oldm->type(),
Type::COMPARE_TAGS, NULL))
go_error_at(tl, "duplicate method %qs",
Gogo::message_name(q->name()).c_str());
{
go_error_at(tl, "duplicate method %qs",
Gogo::message_name(q->name()).c_str());
this->set_is_error();
}
}
}