1
1
mirror of https://github.com/casey/just.git synced 2024-11-29 06:03:58 +03:00

Fix type names in redefinition error message (#2353)

This commit is contained in:
Marc Addeo 2024-09-13 04:45:32 -04:00 committed by GitHub
parent beef0e1a0f
commit 5fb514c1c6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 4 deletions

View File

@ -52,10 +52,10 @@ impl<'src> Analyzer<'src> {
-> CompileResult<'src> { -> CompileResult<'src> {
if let Some((first_type, original)) = definitions.get(name.lexeme()) { if let Some((first_type, original)) = definitions.get(name.lexeme()) {
if !(*first_type == second_type && duplicates_allowed) { if !(*first_type == second_type && duplicates_allowed) {
let (original, redefinition) = if name.line < original.line { let ((first_type, second_type), (original, redefinition)) = if name.line < original.line {
(name, *original) ((second_type, *first_type), (name, *original))
} else { } else {
(*original, name) ((*first_type, second_type), (*original, name))
}; };
return Err(redefinition.token.error(Redefinition { return Err(redefinition.token.error(Redefinition {
@ -383,7 +383,7 @@ mod tests {
line: 2, line: 2,
column: 6, column: 6,
width: 3, 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! { analysis_error! {

View File

@ -109,3 +109,21 @@ fn file_paths_not_in_subdir_are_absolute() {
) )
.run(); .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();
}