Skip to content
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

Duplicate labels when span length is 0 and preceded by a newline #130

Closed
jmackie opened this issue Mar 13, 2022 · 1 comment · Fixed by #159
Closed

Duplicate labels when span length is 0 and preceded by a newline #130

jmackie opened this issue Mar 13, 2022 · 1 comment · Fixed by #159
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@jmackie
Copy link

jmackie commented Mar 13, 2022

I'm seeing strange behaviour when my SourceSpan has length 0 and the byte before the offset is a newline 🤔

Minimal reproducible example:

use miette::{Diagnostic, NamedSource, Result, SourceSpan};
use thiserror::Error;

#[derive(Error, Debug, Diagnostic)]
#[error("oops!")]
#[diagnostic(severity(Error))]
struct MyBad {
    #[source_code]
    src: NamedSource,
    #[label("This bit here")]
    bad_bit: SourceSpan,
}

fn main() -> Result<()> {
    Err(MyBad {
        src: NamedSource::new("issue", "this is the first line\nthis is the second line"),
        bad_bit: (23, 0).into(),
    }
    .into())
}

Gives:

Error:
  × oops!
   ╭─[issue:1:1]
 1 │ this is the first line
   ·                        ▲
   ·                        ╰── This bit here
 2 │ this is the second line
   · ▲
   · ╰── This bit here
   ╰────
@zkat zkat added bug Something isn't working help wanted Extra attention is needed labels Mar 19, 2022
@zkat
Copy link
Owner

zkat commented Mar 19, 2022

Interesting! I don't know what's going on, but I'd love some help with this one. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants