Skip to content

Commit

Permalink
Fix type names in redefinition error message (#2353)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcaddeo committed Sep 13, 2024
1 parent beef0e1 commit 5fb514c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ impl<'src> Analyzer<'src> {
-> CompileResult<'src> {
if let Some((first_type, original)) = definitions.get(name.lexeme()) {
if !(*first_type == second_type && duplicates_allowed) {
let (original, redefinition) = if name.line < original.line {
(name, *original)
let ((first_type, second_type), (original, redefinition)) = if name.line < original.line {
((second_type, *first_type), (name, *original))
} else {
(*original, name)
((*first_type, second_type), (*original, name))
};

return Err(redefinition.token.error(Redefinition {
Expand Down Expand Up @@ -383,7 +383,7 @@ mod tests {
line: 2,
column: 6,
width: 3,
kind: Redefinition { first_type: "alias", second_type: "recipe", name: "foo", first: 0 },
kind: Redefinition { first_type: "recipe", second_type: "alias", name: "foo", first: 0 },
}

analysis_error! {
Expand Down
18 changes: 18 additions & 0 deletions tests/error_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,21 @@ fn file_paths_not_in_subdir_are_absolute() {
)
.run();
}

#[test]
fn redefinition_errors_properly_swap_types() {
Test::new()
.write("foo.just", "foo:")
.justfile("foo:\n echo foo\n\nmod foo 'foo.just'")
.status(EXIT_FAILURE)
.stderr(
"
error: Recipe `foo` defined on line 1 is redefined as a module on line 4
——▶ justfile:4:5
4 │ mod foo 'foo.just'
│ ^^^
",
)
.run();
}

0 comments on commit 5fb514c

Please sign in to comment.