Skip to content

Commit

Permalink
Merge branch 'master' into one
Browse files Browse the repository at this point in the history
  • Loading branch information
casey committed Sep 21, 2024
2 parents ff5caaa + 19018d1 commit 224a06c
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 44 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,12 @@ most Windows users.)
<td><a href=https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/tools/just/default.nix>just</a></td>
<td><code>nix-env -iA nixpkgs.just</code></td>
</tr>
<tr>
<td><a href=https://github.com/pypa/pipx?tab=readme-ov-file#install-pipx>Various</a></td>
<td><a href=https://pypi.org/>PyPI</a></td>
<td><a href=https://pypi.org/project/rust-just/>rust-just</a></td>
<td><code>pipx install rust-just</code></td>
</tr>
<tr>
<td><a href=https://voidlinux.org>Void Linux</a></td>
<td><a href=https://wiki.voidlinux.org/XBPS>XBPS</a></td>
Expand Down
8 changes: 0 additions & 8 deletions src/analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,14 +323,6 @@ impl<'src> Analyzer<'src> {
recipes: &Table<'src, Rc<Recipe<'src>>>,
alias: Alias<'src, Name<'src>>,
) -> CompileResult<'src, Alias<'src>> {
// Make sure the alias doesn't conflict with any recipe
if let Some(recipe) = recipes.get(alias.name.lexeme()) {
return Err(alias.name.token.error(AliasShadowsRecipe {
alias: alias.name.lexeme(),
recipe_line: recipe.line_number(),
}));
}

// Make sure the target recipe exists
match recipes.get(alias.target.lexeme()) {
Some(target) => Ok(alias.resolve(Rc::clone(target))),
Expand Down
6 changes: 0 additions & 6 deletions src/compile_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@ impl Display for CompileError<'_> {
use CompileErrorKind::*;

match &*self.kind {
AliasShadowsRecipe { alias, recipe_line } => write!(
f,
"Alias `{alias}` defined on line {} shadows recipe `{alias}` defined on line {}",
self.token.line.ordinal(),
recipe_line.ordinal(),
),
AttributeArgumentCountMismatch {
attribute,
found,
Expand Down
4 changes: 0 additions & 4 deletions src/compile_error_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ use super::*;

#[derive(Debug, PartialEq)]
pub(crate) enum CompileErrorKind<'src> {
AliasShadowsRecipe {
alias: &'src str,
recipe_line: usize,
},
AttributeArgumentCountMismatch {
attribute: &'src str,
found: usize,
Expand Down
13 changes: 7 additions & 6 deletions src/recipe_resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ impl<'src: 'run, 'run> RecipeResolver<'src, 'run> {
}

for recipe in resolver.resolved_recipes.values() {
for parameter in &recipe.parameters {
for (i, parameter) in recipe.parameters.iter().enumerate() {
if let Some(expression) = &parameter.default {
for variable in expression.variables() {
resolver.resolve_variable(&variable, &[])?;
resolver.resolve_variable(&variable, &recipe.parameters[..i])?;
}
}
}
Expand Down Expand Up @@ -63,11 +63,12 @@ impl<'src: 'run, 'run> RecipeResolver<'src, 'run> {
parameters: &[Parameter],
) -> CompileResult<'src> {
let name = variable.lexeme();
let undefined = !self.assignments.contains_key(name)
&& !parameters.iter().any(|p| p.name.lexeme() == name)
&& !constants().contains_key(name);

if undefined {
let defined = self.assignments.contains_key(name)
|| parameters.iter().any(|p| p.name.lexeme() == name)
|| constants().contains_key(name);

if !defined {
return Err(variable.error(UndefinedVariable { variable: name }));
}

Expand Down
1 change: 1 addition & 0 deletions tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ mod no_cd;
mod no_dependencies;
mod no_exit_message;
mod os_attributes;
mod parameters;
mod parser;
mod positional_arguments;
mod private;
Expand Down
20 changes: 0 additions & 20 deletions tests/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1941,26 +1941,6 @@ test! {
shell: false,
}

test! {
name: parameter_cross_reference_error,
justfile: "
foo:
bar a b=a:
",
args: (),
stdout: "",
stderr: "
error: Variable `a` not defined
β€”β€”β–Ά justfile:3:9
β”‚
3 β”‚ bar a b=a:
β”‚ ^
",
status: EXIT_FAILURE,
shell: false,
}

#[cfg(windows)]
test! {
name: pwsh_invocation_directory,
Expand Down
38 changes: 38 additions & 0 deletions tests/parameters.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use super::*;

#[test]
fn parameter_default_values_may_use_earlier_parameters() {
Test::new()
.justfile(
"
@foo a b=a:
echo {{ b }}
",
)
.args(["foo", "bar"])
.stdout("bar\n")
.run();
}

#[test]
fn parameter_default_values_may_not_use_later_parameters() {
Test::new()
.justfile(
"
@foo a b=c c='':
echo {{ b }}
",
)
.args(["foo", "bar"])
.stderr(
"
error: Variable `c` not defined
β€”β€”β–Ά justfile:1:10
β”‚
1 β”‚ @foo a b=c c='':
β”‚ ^
",
)
.status(EXIT_FAILURE)
.run();
}

0 comments on commit 224a06c

Please sign in to comment.