Fix the auto-conversion regression (#3307)

This commit is contained in:
Jonathan Turner 2021-04-13 14:25:18 +12:00 committed by GitHub
parent fc15e0e27d
commit e09e3b01d6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 36 deletions

View file

@ -63,7 +63,7 @@ impl Iterator for InternalIteratorSimple {
pub struct InternalIterator { pub struct InternalIterator {
pub context: EvaluationContext, pub context: EvaluationContext,
pub leftovers: Vec<Value>, pub leftovers: InputStream,
pub input: ActionStream, pub input: ActionStream,
} }
@ -71,8 +71,7 @@ impl Iterator for InternalIterator {
type Item = Value; type Item = Value;
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {
if !self.leftovers.is_empty() { if let Some(output) = self.leftovers.next() {
let output = self.leftovers.remove(0);
return Some(output); return Some(output);
} }
@ -114,45 +113,24 @@ impl Iterator for InternalIterator {
}, },
scope: self.context.scope.clone(), scope: self.context.scope.clone(),
}; };
let result = converter let result = converter.run(new_args.with_input(vec![tagged_contents]));
.run_with_actions(new_args.with_input(vec![tagged_contents]));
match result { match result {
Ok(mut result) => { Ok(mut result) => {
let result_vec: Vec<Result<ReturnSuccess, ShellError>> = if let Some(x) = result.next() {
result.drain_vec(); self.leftovers =
InputStream::from_stream(result.map(move |x| Value {
let mut output = vec![]; value: x.value,
for res in result_vec { tag: contents_tag.clone(),
match res { }));
Ok(ReturnSuccess::Value(Value {
value: UntaggedValue::Table(list),
..
})) => {
for l in list {
output.push(l);
}
}
Ok(ReturnSuccess::Value(Value { value, .. })) => {
output.push(value.into_value(contents_tag.clone()));
}
Err(e) => output.push(
UntaggedValue::Error(e).into_untagged_value(),
),
_ => {}
}
}
let mut output = output.into_iter();
if let Some(x) = output.next() {
self.leftovers = output.collect();
return Some(x); return Some(x);
} else {
return None;
} }
} }
Err(err) => { Err(err) => {
self.context.error(err); self.leftovers = InputStream::empty();
return Some(Value::error(err));
} }
} }
} else { } else {

View file

@ -38,7 +38,7 @@ pub trait WholeStreamCommand: Send + Sync {
Ok(Box::new(crate::evaluate::internal::InternalIterator { Ok(Box::new(crate::evaluate::internal::InternalIterator {
context, context,
input: stream, input: stream,
leftovers: vec![], leftovers: InputStream::empty(),
}) })
.to_output_stream()) .to_output_stream())
} }

View file

@ -44,9 +44,11 @@ impl ActionStream {
pub fn drain_vec(&mut self) -> Vec<ReturnValue> { pub fn drain_vec(&mut self) -> Vec<ReturnValue> {
let mut output = vec![]; let mut output = vec![];
while let Some(x) = self.values.next() { while let Some(x) = self.values.next() {
output.push(x); output.push(x);
} }
output output
} }
} }