Merge pull request #282 from Johann150/patch-6

fix locus calculation
This commit is contained in:
Brendan Zabarauskas 2020-09-04 21:46:28 +10:00 committed by GitHub
commit 3f8907ce36
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 5 deletions

View File

@ -113,7 +113,7 @@ impl<FileId> Label<FileId> {
/// Represents a diagnostic message that can provide information like errors and
/// warnings to the user.
///
/// The position of a Diagnostic is considered to be the position of the [`Label`] with a style of [`LabelStyle::primary`] that has the smallest start position.
/// The position of a Diagnostic is considered to be the position of the [`Label`] that has the earliest starting position and has the highest style which appears in all the labels of the diagnostic.
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
pub struct Diagnostic<FileId> {

View File

@ -123,10 +123,11 @@ where
{
Some(labeled_file) => {
// another diagnostic also referenced this file
if labeled_file.start > label.range.start
&& labeled_file.max_label_style >= label.style
if labeled_file.max_label_style > label.style
|| (labeled_file.max_label_style == label.style
&& labeled_file.start > label.range.start)
{
// this label indicates an earlier start and has at least the same level of style
// this label has a higher style or has the same style but starts earlier
labeled_file.start = label.range.start;
labeled_file.location = files
.location(label.file_id, label.range.start)

View File

@ -569,9 +569,10 @@ mod multiline_overlapping {
.with_message("match arms have incompatible types")
.with_code("E0308")
.with_labels(vec![
// this secondary label is before the primary label to test the locus calculation (see issue #259)
Label::secondary((), 89..134).with_message("this is found to be of type `Result<ByteIndex, LineIndexOutOfBoundsError>`"),
Label::primary((), 230..351).with_message("expected enum `Result`, found struct `LineIndexOutOfBoundsError`"),
Label::secondary((), 8..362).with_message("`match` arms have incompatible types"),
Label::secondary((), 89..134).with_message("this is found to be of type `Result<ByteIndex, LineIndexOutOfBoundsError>`"),
Label::secondary((), 167..195).with_message("this is found to be of type `Result<ByteIndex, LineIndexOutOfBoundsError>`"),
])
.with_notes(vec![unindent::unindent(