-
Notifications
You must be signed in to change notification settings - Fork 10.5k
DiagnosticVerifier: Support line offsets in fix-it verification ranges #41429
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DiagnosticVerifier: Support line offsets in fix-it verification ranges #41429
Conversation
@swift-ci please smoke test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! Just a few comments about code styling. Implementation looks pretty good
lib/Frontend/DiagnosticVerifier.cpp
Outdated
|
||
if (secondValue == LineColumnRange::NoValue) { | ||
// If only one value is specified, it's a column number; | ||
return std::make_pair(secondValue, firstValue); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a little bit confusing. I feel std::make_pair(LineColumnRange::NoValue, firstValue)
is more clear.
lib/Frontend/DiagnosticVerifier.cpp
Outdated
switch (lineOffsetKind) { | ||
case LineOffsetKind::None: | ||
break; | ||
case LineOffsetKind::Plus: | ||
firstValue += DiagnosticLineNo; | ||
break; | ||
case LineOffsetKind::Minus: | ||
firstValue = DiagnosticLineNo - firstValue; | ||
break; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
auto lineNo = DiagnosticLineNo;
switch (lineOffsetKind) {
case ::None
lineNo = firstValue;
break;
case ::Plus
lineNo += firstValue;
break;
case ::Minus
lineNo -= firstValue;
break;
}
WDYT?
lib/Frontend/DiagnosticVerifier.cpp
Outdated
const enum class LineOffsetKind : uint8_t { | ||
None, | ||
Plus, | ||
Minus | ||
} lineOffsetKind = [&] { | ||
if (Str.empty()) | ||
return LineOffsetKind::None; | ||
|
||
switch (Str.front()) { | ||
case '+': | ||
return LineOffsetKind::Plus; | ||
case '-': | ||
return LineOffsetKind::Minus; | ||
default: | ||
return LineOffsetKind::None; | ||
} | ||
}(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clever, but
const enum class LineOffsetKind : uint8_t {
None,
Plus,
Minus
};
LineOffsetKind lineOffsetKind = LineOffsetKind::None;
switch (Str.front()) {
case '+':
lineOffsetKind = LineOffsetKind::Plus;
Str = Str.drop_front();
break;
case '-':
lineOffsetKind = LineOffsetKind::Minus;
Str = Str.drop_front();
break;
default:
break;
}
feels easier to read.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had the feeling this was gonna bug someone 😄
No problem, can I keep the lambda for constness though? When reading C++, I feel a ton of relief every time I see that something's not going to be mutated in the next 50+ lines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, never mind; the difference looks negligible this time.
4b58d9b
to
2128678
Compare
@swift-ci Please smoke test |
@rintaro Appreciate the review! |
Follow-up to #39572
The range syntax is now
([+-]?N:)?N-([+-]?N:)?N
whereN
is[0-9]+
.