Skip to content

Commit be9d805

Browse files
committed
Don't continue emitting a declaration that has sema errors, regardless 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.
1 parent 442d17c commit be9d805

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

source/sema.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1505,9 +1505,15 @@ class sema
15051505
return true;
15061506
}
15071507

1508-
auto check(declaration_node const& n)
1508+
auto check(
1509+
declaration_node const& n,
1510+
bool emit_errors = true // pass false to validate checks only
1511+
)
15091512
-> bool
15101513
{
1514+
std::vector<error_entry> devnull;
1515+
auto& errors = emit_errors ? this->errors : devnull;
1516+
15111517
if (n.has_name("operator")) {
15121518
errors.emplace_back(
15131519
n.position(),

source/to_cpp1.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5492,11 +5492,8 @@ class cppfront
54925492

54935493

54945494
// Declarations are handled in multiple passes,
5495-
// but we only want to do the sema checks once
5496-
if (
5497-
printer.get_phase() == printer.phase2_func_defs
5498-
&& !sema.check(n)
5499-
)
5495+
// but we only want to emit the error messages once (in phase 2)
5496+
if (!sema.check(n, printer.get_phase() == printer.phase2_func_defs))
55005497
{
55015498
return;
55025499
}

0 commit comments

Comments
 (0)