-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
EmitterWriter::get_max_line_num works incorrectly #64447
Copy link
Copy link
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
TL;DR:
EmitterWriter::get_max_line_numunconditionally returnsself.get_multispan_max_line_num(span)no matter what is contained inchildren.Longer explanation: let's take a look at the code of method (it's rather short):
Here
self.get_multispan_max_line_num(span)returns a plainusize. Firstly, since0is the smallest possible value ofusize, the first three lines can be rewritten without changing the meaning asSo after executing these lines
max == primary. Secondly, in the loopifcomparessub_resultwithmaxbut assigns eithermaxorprimary. Ifmax == primaryin the beginning of iteration, then this also holds in the end of iteration. Since this preposition holds before executing the loop, it also holds after executing the loop, so the whole method just returnsprimary, QED.Erroneous code was introduced in 71ec286.
Unfortunately, I'm not familliar enough with the code to propose the correct fix.