mirror of
https://github.com/nushell/nushell.git
synced 2025-07-01 23:22:10 +02:00
Remove Signature.vectorizes_over_list
entirely (#9777)
# Description With the current typechecking logic this property has no effect. It was only used in the example testing, and provided some indication of this vectorizing property. With #9742 all commands that previously declared it have explicit list signatures. If we want to get it back in the future we can reconstruct it from the signature. Simplifies the example testing a bit. # User-Facing Changes Causes a breaking change for plugins that previously declared it. While this causes a compile fail, this was already broken by our more stringent type checking. This will be a good reminder for plugin authors to update their signature as well to reflect the more stringent type checking.
This commit is contained in:
committed by
GitHub
parent
d9230a76f3
commit
b2e191f836
@ -12,7 +12,6 @@ pub fn check_example_input_and_output_types_match_command_signature(
|
||||
engine_state: &mut Box<EngineState>,
|
||||
signature_input_output_types: &Vec<(Type, Type)>,
|
||||
signature_operates_on_cell_paths: bool,
|
||||
signature_vectorizes_over_list: bool,
|
||||
) -> HashSet<(Type, Type)> {
|
||||
let mut witnessed_type_transformations = HashSet::<(Type, Type)>::new();
|
||||
|
||||
@ -37,40 +36,6 @@ pub fn check_example_input_and_output_types_match_command_signature(
|
||||
}
|
||||
});
|
||||
|
||||
// The example type checks as vectorization over an input list if both:
|
||||
// 1. The command is declared to vectorize over list input.
|
||||
// 2. There exists an entry t -> u in the type map such that the
|
||||
// example_input_type is a subtype of list<t> and the
|
||||
// example_output_type is a subtype of list<u>.
|
||||
let example_matches_signature_via_vectorization_over_list =
|
||||
signature_vectorizes_over_list
|
||||
&& match &example_input_type {
|
||||
Type::List(ex_in_type) => {
|
||||
match signature_input_output_types.iter().find_map(
|
||||
|(sig_in_type, sig_out_type)| {
|
||||
if ex_in_type.is_subtype(sig_in_type) {
|
||||
Some((sig_in_type, sig_out_type))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
},
|
||||
) {
|
||||
Some((sig_in_type, sig_out_type)) => match &example_output_type {
|
||||
Type::List(ex_out_type)
|
||||
if ex_out_type.is_subtype(sig_out_type) =>
|
||||
{
|
||||
witnessed_type_transformations
|
||||
.insert((sig_in_type.clone(), sig_out_type.clone()));
|
||||
true
|
||||
}
|
||||
_ => false,
|
||||
},
|
||||
None => false,
|
||||
}
|
||||
}
|
||||
_ => false,
|
||||
};
|
||||
|
||||
// The example type checks as a cell path operation if both:
|
||||
// 1. The command is declared to operate on cell paths.
|
||||
// 2. The example_input_type is list or record or table, and the example
|
||||
@ -80,22 +45,22 @@ pub fn check_example_input_and_output_types_match_command_signature(
|
||||
// TODO: This is too permissive; it should make use of the signature.input_output_types at least.
|
||||
&& example_output_type.to_shape() == example_input_type.to_shape();
|
||||
|
||||
if !(example_matches_signature
|
||||
|| example_matches_signature_via_vectorization_over_list
|
||||
|| example_matches_signature_via_cell_path_operation)
|
||||
{
|
||||
if !(example_matches_signature || example_matches_signature_via_cell_path_operation) {
|
||||
panic!(
|
||||
"The example `{}` demonstrates a transformation of type {:?} -> {:?}. \
|
||||
"The example `{}` demonstrates a transformation of type {:?} -> {:?}. \
|
||||
However, this does not match the declared signature: {:?}.{} \
|
||||
For this command, `vectorizes_over_list` is {} and `operates_on_cell_paths()` is {}.",
|
||||
example.example,
|
||||
example_input_type,
|
||||
example_output_type,
|
||||
signature_input_output_types,
|
||||
if signature_input_output_types.is_empty() { " (Did you forget to declare the input and output types for the command?)" } else { "" },
|
||||
signature_vectorizes_over_list,
|
||||
signature_operates_on_cell_paths
|
||||
);
|
||||
For this command `operates_on_cell_paths()` is {}.",
|
||||
example.example,
|
||||
example_input_type,
|
||||
example_output_type,
|
||||
signature_input_output_types,
|
||||
if signature_input_output_types.is_empty() {
|
||||
" (Did you forget to declare the input and output types for the command?)"
|
||||
} else {
|
||||
""
|
||||
},
|
||||
signature_operates_on_cell_paths
|
||||
);
|
||||
};
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user