Skip to content

Commit

Permalink
Don't continue emitting a declaration that has sema errors, regardles…
Browse files Browse the repository at this point in the history
…s of phase

Closes #1124
Closes #1123

I think the key #1123 and #1124 are exposing is that we shouldn't be continuing past the point where sema checks fail (we already know there's an error), but we aren't doing the sema checks purely because declarations are multi-phase so I only call the checks on phase 2 to avoid duplicate error messages... but that means that in the other phases we're not doing the checks and continuing as if the code is legal.

So here's an update to ensure the checks are always called so that the function won't continue if errors have already been found, but we still only actually emit the errors in phase 2. It's slightly wasteful to write duplicate messages to a local container, but hey, it only happens if there are error messages and there shouldn't be large numbers of them.
  • Loading branch information
hsutter committed Jun 20, 2024
1 parent 442d17c commit be9d805
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
8 changes: 7 additions & 1 deletion source/sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -1505,9 +1505,15 @@ class sema
return true;
}

auto check(declaration_node const& n)
auto check(
declaration_node const& n,
bool emit_errors = true // pass false to validate checks only
)
-> bool
{
std::vector<error_entry> devnull;
auto& errors = emit_errors ? this->errors : devnull;

if (n.has_name("operator")) {
errors.emplace_back(
n.position(),
Expand Down
7 changes: 2 additions & 5 deletions source/to_cpp1.h
Original file line number Diff line number Diff line change
Expand Up @@ -5492,11 +5492,8 @@ class cppfront


// Declarations are handled in multiple passes,
// but we only want to do the sema checks once
if (
printer.get_phase() == printer.phase2_func_defs
&& !sema.check(n)
)
// but we only want to emit the error messages once (in phase 2)
if (!sema.check(n, printer.get_phase() == printer.phase2_func_defs))
{
return;
}
Expand Down

0 comments on commit be9d805

Please sign in to comment.