mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 14:40:06 +02:00
Remove broken compile-time overload system (#9677)
# Description This PR removes the compile-time overload system. Unfortunately, this system never worked correctly because in a gradual type system where types can be `Any`, you don't have enough information to correctly resolve function calls with overloads. These resolutions must be done at runtime, if they're supported. That said, there's a bit of work that needs to go into resolving input/output types (here overloads do not execute separate commands, but the same command and each overload explains how each output type corresponds to input types). This PR also removes the type scope, which would give incorrect answers in cases where multiple subexpressions were used in a pipeline. # User-Facing Changes Finishes removing compile-time overloads. These were only used in a few places in the code base, but it's possible it may impact user code. I'll mark this as breaking change so we can review. # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- -c "use std testing; testing run-tests --path crates/nu-std"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
This commit is contained in:
@ -1590,177 +1590,6 @@ mod input_types {
|
||||
.expect("Error merging delta");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn call_types_test() {
|
||||
let mut engine_state = EngineState::new();
|
||||
add_declarations(&mut engine_state);
|
||||
|
||||
let mut working_set = StateWorkingSet::new(&engine_state);
|
||||
let input = r#"ls | to-custom | group-by name other"#;
|
||||
|
||||
let block = parse(&mut working_set, None, input.as_bytes(), true);
|
||||
|
||||
assert!(working_set.parse_errors.is_empty());
|
||||
assert_eq!(block.len(), 1);
|
||||
|
||||
let expressions = &block[0];
|
||||
assert_eq!(expressions.len(), 3);
|
||||
|
||||
match &expressions[0] {
|
||||
PipelineElement::Expression(
|
||||
_,
|
||||
Expression {
|
||||
expr: Expr::Call(call),
|
||||
..
|
||||
},
|
||||
) => {
|
||||
let expected_id = working_set
|
||||
.find_decl(b"ls", &Type::Nothing)
|
||||
.expect("Error merging delta");
|
||||
assert_eq!(call.decl_id, expected_id)
|
||||
}
|
||||
_ => panic!("Expected expression Call not found"),
|
||||
}
|
||||
|
||||
match &expressions[1] {
|
||||
PipelineElement::Expression(
|
||||
_,
|
||||
Expression {
|
||||
expr: Expr::Call(call),
|
||||
..
|
||||
},
|
||||
) => {
|
||||
let expected_id = working_set.find_decl(b"to-custom", &Type::Any).unwrap();
|
||||
assert_eq!(call.decl_id, expected_id)
|
||||
}
|
||||
_ => panic!("Expected expression Call not found"),
|
||||
}
|
||||
|
||||
match &expressions[2] {
|
||||
PipelineElement::Expression(
|
||||
_,
|
||||
Expression {
|
||||
expr: Expr::Call(call),
|
||||
..
|
||||
},
|
||||
) => {
|
||||
let expected_id = working_set
|
||||
.find_decl(b"group-by", &Type::Custom("custom".into()))
|
||||
.unwrap();
|
||||
assert_eq!(call.decl_id, expected_id)
|
||||
}
|
||||
_ => panic!("Expected expression Call not found"),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn storing_variable_test() {
|
||||
let mut engine_state = EngineState::new();
|
||||
add_declarations(&mut engine_state);
|
||||
|
||||
let mut working_set = StateWorkingSet::new(&engine_state);
|
||||
let input =
|
||||
r#"let a = (ls | to-custom | group-by name other); let b = (1+3); $a | agg sum"#;
|
||||
|
||||
let block = parse(&mut working_set, None, input.as_bytes(), true);
|
||||
|
||||
assert!(working_set.parse_errors.is_empty());
|
||||
assert_eq!(block.len(), 3);
|
||||
|
||||
let expressions = &block[2];
|
||||
match &expressions[1] {
|
||||
PipelineElement::Expression(
|
||||
_,
|
||||
Expression {
|
||||
expr: Expr::Call(call),
|
||||
..
|
||||
},
|
||||
) => {
|
||||
let expected_id = working_set
|
||||
.find_decl(b"agg", &Type::Custom("custom".into()))
|
||||
.unwrap();
|
||||
assert_eq!(call.decl_id, expected_id)
|
||||
}
|
||||
_ => panic!("Expected expression Call not found"),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stored_variable_operation_test() {
|
||||
let mut engine_state = EngineState::new();
|
||||
add_declarations(&mut engine_state);
|
||||
|
||||
let mut working_set = StateWorkingSet::new(&engine_state);
|
||||
let input = r#"let a = (ls | to-custom | group-by name other); ($a + $a) | agg sum"#;
|
||||
|
||||
let block = parse(&mut working_set, None, input.as_bytes(), true);
|
||||
|
||||
assert!(working_set.parse_errors.is_empty());
|
||||
assert_eq!(block.len(), 2);
|
||||
|
||||
let expressions = &block[1];
|
||||
match &expressions[1] {
|
||||
PipelineElement::Expression(
|
||||
_,
|
||||
Expression {
|
||||
expr: Expr::Call(call),
|
||||
..
|
||||
},
|
||||
) => {
|
||||
let expected_id = working_set
|
||||
.find_decl(b"agg", &Type::Custom("custom".into()))
|
||||
.unwrap();
|
||||
assert_eq!(call.decl_id, expected_id)
|
||||
}
|
||||
_ => panic!("Expected expression Call not found"),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn multiple_stored_variable_test() {
|
||||
let mut engine_state = EngineState::new();
|
||||
add_declarations(&mut engine_state);
|
||||
|
||||
let mut working_set = StateWorkingSet::new(&engine_state);
|
||||
let input = r#"
|
||||
let a = (ls | to-custom | group-by name other); [1 2 3] | to-custom; [1 2 3] | to-custom"#;
|
||||
|
||||
let block = parse(&mut working_set, None, input.as_bytes(), true);
|
||||
|
||||
assert!(working_set.parse_errors.is_empty());
|
||||
assert_eq!(block.len(), 3);
|
||||
|
||||
let expressions = &block[1];
|
||||
match &expressions[1] {
|
||||
PipelineElement::Expression(
|
||||
_,
|
||||
Expression {
|
||||
expr: Expr::Call(call),
|
||||
..
|
||||
},
|
||||
) => {
|
||||
let expected_id = working_set.find_decl(b"to-custom", &Type::Any).unwrap();
|
||||
assert_eq!(call.decl_id, expected_id)
|
||||
}
|
||||
_ => panic!("Expected expression Call not found"),
|
||||
}
|
||||
|
||||
let expressions = &block[2];
|
||||
match &expressions[1] {
|
||||
PipelineElement::Expression(
|
||||
_,
|
||||
Expression {
|
||||
expr: Expr::Call(call),
|
||||
..
|
||||
},
|
||||
) => {
|
||||
let expected_id = working_set.find_decl(b"to-custom", &Type::Any).unwrap();
|
||||
assert_eq!(call.decl_id, expected_id)
|
||||
}
|
||||
_ => panic!("Expected expression Call not found"),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn call_non_custom_types_test() {
|
||||
let mut engine_state = EngineState::new();
|
||||
@ -1785,7 +1614,7 @@ mod input_types {
|
||||
..
|
||||
},
|
||||
) => {
|
||||
let expected_id = working_set.find_decl(b"ls", &Type::Nothing).unwrap();
|
||||
let expected_id = working_set.find_decl(b"ls").unwrap();
|
||||
assert_eq!(call.decl_id, expected_id)
|
||||
}
|
||||
_ => panic!("Expected expression Call not found"),
|
||||
@ -1799,7 +1628,7 @@ mod input_types {
|
||||
..
|
||||
},
|
||||
) => {
|
||||
let expected_id = working_set.find_decl(b"group-by", &Type::Any).unwrap();
|
||||
let expected_id = working_set.find_decl(b"group-by").unwrap();
|
||||
assert_eq!(call.decl_id, expected_id)
|
||||
}
|
||||
_ => panic!("Expected expression Call not found"),
|
||||
@ -1849,8 +1678,7 @@ mod input_types {
|
||||
},
|
||||
) => {
|
||||
let working_set = StateWorkingSet::new(&engine_state);
|
||||
let expected_id =
|
||||
working_set.find_decl(b"min", &Type::Any).unwrap();
|
||||
let expected_id = working_set.find_decl(b"min").unwrap();
|
||||
assert_eq!(call.decl_id, expected_id)
|
||||
}
|
||||
_ => panic!("Expected expression Call not found"),
|
||||
@ -1889,9 +1717,7 @@ mod input_types {
|
||||
..
|
||||
},
|
||||
) => {
|
||||
let expected_id = working_set
|
||||
.find_decl(b"with-column", &Type::Custom("custom".into()))
|
||||
.unwrap();
|
||||
let expected_id = working_set.find_decl(b"with-column").unwrap();
|
||||
assert_eq!(call.decl_id, expected_id)
|
||||
}
|
||||
_ => panic!("Expected expression Call not found"),
|
||||
@ -1905,9 +1731,7 @@ mod input_types {
|
||||
..
|
||||
},
|
||||
) => {
|
||||
let expected_id = working_set
|
||||
.find_decl(b"collect", &Type::Custom("custom".into()))
|
||||
.unwrap();
|
||||
let expected_id = working_set.find_decl(b"collect").unwrap();
|
||||
assert_eq!(call.decl_id, expected_id)
|
||||
}
|
||||
_ => panic!("Expected expression Call not found"),
|
||||
|
Reference in New Issue
Block a user