Remove the Value::Block case (#12582)

# Description
`Value` describes the types of first-class values that users and scripts
can create, manipulate, pass around, and store. However, `Block`s are
not first-class values in the language, so this PR removes it from
`Value`. This removes some unnecessary code, and this change should be
invisible to the user except for the change to `scope modules` described
below.

# User-Facing Changes
Breaking change: the output of `scope modules` was changed so that
`env_block` is now `has_env_block` which is a boolean value instead of a
`Block`.

# After Submitting
Update the language guide possibly.
This commit is contained in:
Ian Manske
2024-04-21 05:03:33 +00:00
committed by GitHub
parent 5fd34320e9
commit 3b1d405b96
32 changed files with 171 additions and 352 deletions

View File

@@ -36,8 +36,8 @@ impl ReconstructVal for CompletionAlgorithm {
}
pub(super) fn reconstruct_external_completer(config: &Config, span: Span) -> Value {
if let Some(block) = config.external_completer {
Value::block(block, span)
if let Some(closure) = config.external_completer.as_ref() {
Value::closure(closure.clone(), span)
} else {
Value::nothing(span)
}

View File

@@ -5,6 +5,7 @@ use self::output::*;
use self::reedline::*;
use self::table::*;
use crate::engine::Closure;
use crate::{record, ShellError, Span, Value};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
@@ -48,7 +49,7 @@ impl Default for HistoryConfig {
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct Config {
pub external_completer: Option<usize>,
pub external_completer: Option<Closure>,
pub filesize_metric: bool,
pub table_mode: TableMode,
pub table_move_header: bool,
@@ -334,13 +335,13 @@ impl Value {
process_int_config(value, &mut errors, &mut config.max_external_completion_results);
}
"completer" => {
if let Ok(v) = value.coerce_block() {
config.external_completer = Some(v)
if let Ok(v) = value.as_closure() {
config.external_completer = Some(v.clone())
} else {
match value {
Value::Nothing { .. } => {}
_ => {
report_invalid_value("should be a block or null", span, &mut errors);
report_invalid_value("should be a closure or null", span, &mut errors);
// Reconstruct
*value = reconstruct_external_completer(&config,
span