Use new syntax for None values
This commit is contained in:
parent
d2def28751
commit
bf79526764
@ -103,7 +103,7 @@ impl AbstractTree for Assignment {
|
|||||||
statement_type
|
statement_type
|
||||||
};
|
};
|
||||||
|
|
||||||
context.set(variable_key, Value::Option(None), Some(variable_type))?;
|
context.set(variable_key, Value::none(), Some(variable_type))?;
|
||||||
|
|
||||||
Ok(Assignment {
|
Ok(Assignment {
|
||||||
identifier,
|
identifier,
|
||||||
@ -143,7 +143,7 @@ impl AbstractTree for Assignment {
|
|||||||
context.set(key.clone(), new_value, None)?;
|
context.set(key.clone(), new_value, None)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Value::Option(None))
|
Ok(Value::none())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expected_type(&self, _context: &Map) -> Result<Type> {
|
fn expected_type(&self, _context: &Map) -> Result<Type> {
|
||||||
|
@ -52,7 +52,7 @@ impl AbstractTree for Block {
|
|||||||
fn run(&self, source: &str, context: &Map) -> Result<Value> {
|
fn run(&self, source: &str, context: &Map) -> Result<Value> {
|
||||||
if self.is_async {
|
if self.is_async {
|
||||||
let statements = &self.statements;
|
let statements = &self.statements;
|
||||||
let final_result = RwLock::new(Ok(Value::Option(None)));
|
let final_result = RwLock::new(Ok(Value::none()));
|
||||||
|
|
||||||
statements
|
statements
|
||||||
.into_par_iter()
|
.into_par_iter()
|
||||||
@ -74,7 +74,7 @@ impl AbstractTree for Block {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.unwrap_or(final_result.into_inner().unwrap())
|
.unwrap_or(final_result.into_inner()?)
|
||||||
} else {
|
} else {
|
||||||
let mut prev_result = None;
|
let mut prev_result = None;
|
||||||
|
|
||||||
@ -86,7 +86,7 @@ impl AbstractTree for Block {
|
|||||||
prev_result = Some(statement.run(source, context));
|
prev_result = Some(statement.run(source, context));
|
||||||
}
|
}
|
||||||
|
|
||||||
prev_result.unwrap_or(Ok(Value::Option(None)))
|
prev_result.unwrap_or(Ok(Value::none()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ impl AbstractTree for For {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Value::Option(None))
|
Ok(Value::none())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expected_type(&self, _context: &Map) -> Result<Type> {
|
fn expected_type(&self, _context: &Map) -> Result<Type> {
|
||||||
|
@ -76,7 +76,7 @@ impl AbstractTree for IfElse {
|
|||||||
if let Some(block) = &self.else_block {
|
if let Some(block) = &self.else_block {
|
||||||
block.run(source, context)
|
block.run(source, context)
|
||||||
} else {
|
} else {
|
||||||
Ok(Value::Option(None))
|
Ok(Value::none())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ impl AbstractTree for IndexAssignment {
|
|||||||
previous_value += value;
|
previous_value += value;
|
||||||
previous_value
|
previous_value
|
||||||
} else {
|
} else {
|
||||||
Value::Option(None)
|
Value::none()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
AssignmentOperator::MinusEqual => {
|
AssignmentOperator::MinusEqual => {
|
||||||
@ -80,7 +80,7 @@ impl AbstractTree for IndexAssignment {
|
|||||||
previous_value -= value;
|
previous_value -= value;
|
||||||
previous_value
|
previous_value
|
||||||
} else {
|
} else {
|
||||||
Value::Option(None)
|
Value::none()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
AssignmentOperator::Equal => value,
|
AssignmentOperator::Equal => value,
|
||||||
@ -88,7 +88,7 @@ impl AbstractTree for IndexAssignment {
|
|||||||
|
|
||||||
index_context.set(index_key.clone(), new_value, None)?;
|
index_context.set(index_key.clone(), new_value, None)?;
|
||||||
|
|
||||||
Ok(Value::Option(None))
|
Ok(Value::none())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expected_type(&self, _context: &Map) -> Result<Type> {
|
fn expected_type(&self, _context: &Map) -> Result<Type> {
|
||||||
|
@ -72,7 +72,7 @@ impl AbstractTree for Match {
|
|||||||
if let Some(fallback) = &self.fallback {
|
if let Some(fallback) = &self.fallback {
|
||||||
fallback.run(source, context)
|
fallback.run(source, context)
|
||||||
} else {
|
} else {
|
||||||
Ok(Value::Option(None))
|
Ok(Value::none())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ impl AbstractTree for Root {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn run(&self, source: &str, context: &Map) -> Result<Value> {
|
fn run(&self, source: &str, context: &Map) -> Result<Value> {
|
||||||
let mut value = Value::Option(None);
|
let mut value = Value::none();
|
||||||
|
|
||||||
for statement in &self.statements {
|
for statement in &self.statements {
|
||||||
value = statement.run(source, context)?;
|
value = statement.run(source, context)?;
|
||||||
|
@ -215,7 +215,7 @@ impl AbstractTree for Type {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn run(&self, _source: &str, _context: &Map) -> Result<Value> {
|
fn run(&self, _source: &str, _context: &Map) -> Result<Value> {
|
||||||
Ok(Value::Option(None))
|
Ok(Value::none())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expected_type(&self, _context: &Map) -> Result<Type> {
|
fn expected_type(&self, _context: &Map) -> Result<Type> {
|
||||||
|
@ -57,7 +57,7 @@ impl AbstractTree for ValueNode {
|
|||||||
{
|
{
|
||||||
function_context.set(
|
function_context.set(
|
||||||
parameter_name.inner().clone(),
|
parameter_name.inner().clone(),
|
||||||
Value::Option(None),
|
Value::none(),
|
||||||
Some(parameter_type.clone()),
|
Some(parameter_type.clone()),
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ impl AbstractTree for While {
|
|||||||
self.block.run(source, context)?;
|
self.block.run(source, context)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Value::Option(None))
|
Ok(Value::none())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expected_type(&self, context: &Map) -> Result<Type> {
|
fn expected_type(&self, context: &Map) -> Result<Type> {
|
||||||
|
@ -14,7 +14,7 @@ impl BuiltInFunction for Assert {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Value::Option(None))
|
Ok(Value::none())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn r#type(&self) -> Type {
|
fn r#type(&self) -> Type {
|
||||||
@ -39,7 +39,7 @@ impl BuiltInFunction for AssertEqual {
|
|||||||
let right = arguments.get(1).unwrap();
|
let right = arguments.get(1).unwrap();
|
||||||
|
|
||||||
if left == right {
|
if left == right {
|
||||||
Ok(Value::Option(None))
|
Ok(Value::none())
|
||||||
} else {
|
} else {
|
||||||
Err(Error::AssertEqualFailed {
|
Err(Error::AssertEqualFailed {
|
||||||
expected: left.clone(),
|
expected: left.clone(),
|
||||||
|
@ -65,7 +65,7 @@ impl BuiltInFunction for Write {
|
|||||||
|
|
||||||
write(path, file_content)?;
|
write(path, file_content)?;
|
||||||
|
|
||||||
Ok(Value::Option(None))
|
Ok(Value::none())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn r#type(&self) -> Type {
|
fn r#type(&self) -> Type {
|
||||||
@ -86,11 +86,11 @@ impl BuiltInFunction for Append {
|
|||||||
fn run(&self, arguments: &[Value], _context: &Map) -> Result<Value> {
|
fn run(&self, arguments: &[Value], _context: &Map) -> Result<Value> {
|
||||||
let file_content = arguments
|
let file_content = arguments
|
||||||
.first()
|
.first()
|
||||||
.unwrap_or(&Value::Option(None))
|
.unwrap_or(&Value::none())
|
||||||
.as_string()?;
|
.as_string()?;
|
||||||
let path = arguments
|
let path = arguments
|
||||||
.get(1)
|
.get(1)
|
||||||
.unwrap_or(&Value::Option(None))
|
.unwrap_or(&Value::none())
|
||||||
.as_string()?;
|
.as_string()?;
|
||||||
|
|
||||||
File::options()
|
File::options()
|
||||||
@ -99,7 +99,7 @@ impl BuiltInFunction for Append {
|
|||||||
.open(path)?
|
.open(path)?
|
||||||
.write_all(file_content.as_bytes())?;
|
.write_all(file_content.as_bytes())?;
|
||||||
|
|
||||||
Ok(Value::Option(None))
|
Ok(Value::none())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn r#type(&self) -> Type {
|
fn r#type(&self) -> Type {
|
||||||
|
@ -23,7 +23,7 @@ impl BuiltInFunction for InstallPackages {
|
|||||||
|
|
||||||
command.spawn()?.wait()?;
|
command.spawn()?.wait()?;
|
||||||
|
|
||||||
Ok(Value::Option(None))
|
Ok(Value::none())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn r#type(&self) -> Type {
|
fn r#type(&self) -> Type {
|
||||||
|
@ -58,7 +58,7 @@ impl Map {
|
|||||||
|
|
||||||
pub fn unset_all(&self) -> Result<()> {
|
pub fn unset_all(&self) -> Result<()> {
|
||||||
for (_key, (value, r#_type)) in self.variables.write()?.iter_mut() {
|
for (_key, (value, r#_type)) in self.variables.write()?.iter_mut() {
|
||||||
*value = Value::Option(None);
|
*value = Value::none();
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -234,7 +234,7 @@ impl Value {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `()`, or returns `Err` if `self` is not a `Value::Option(None)`.
|
/// Returns `()`, or returns `Err` if `self` is not a `Value::none()`.
|
||||||
pub fn as_none(&self) -> Result<()> {
|
pub fn as_none(&self) -> Result<()> {
|
||||||
match self {
|
match self {
|
||||||
Value::Option(option) => {
|
Value::Option(option) => {
|
||||||
@ -546,7 +546,7 @@ impl From<Value> for Result<Value> {
|
|||||||
|
|
||||||
impl From<()> for Value {
|
impl From<()> for Value {
|
||||||
fn from(_: ()) -> Self {
|
fn from(_: ()) -> Self {
|
||||||
Value::Option(None)
|
Value::none()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -769,7 +769,7 @@ impl<'de> Visitor<'de> for ValueVisitor {
|
|||||||
where
|
where
|
||||||
E: serde::de::Error,
|
E: serde::de::Error,
|
||||||
{
|
{
|
||||||
Ok(Value::Option(None))
|
Ok(Value::none())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_some<D>(self, deserializer: D) -> std::result::Result<Self::Value, D::Error>
|
fn visit_some<D>(self, deserializer: D) -> std::result::Result<Self::Value, D::Error>
|
||||||
@ -787,7 +787,7 @@ impl<'de> Visitor<'de> for ValueVisitor {
|
|||||||
where
|
where
|
||||||
E: serde::de::Error,
|
E: serde::de::Error,
|
||||||
{
|
{
|
||||||
Ok(Value::Option(None))
|
Ok(Value::none())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_newtype_struct<D>(self, deserializer: D) -> std::result::Result<Self::Value, D::Error>
|
fn visit_newtype_struct<D>(self, deserializer: D) -> std::result::Result<Self::Value, D::Error>
|
||||||
|
@ -81,13 +81,13 @@ mod for_loop {
|
|||||||
fn modify_value_async() {
|
fn modify_value_async() {
|
||||||
let result = interpret(
|
let result = interpret(
|
||||||
"
|
"
|
||||||
list = []
|
fn = (x <int>) <none> {}
|
||||||
async for i in [1 2 3] { list += i }
|
|
||||||
length(list)
|
fn(1)
|
||||||
",
|
",
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(Ok(Value::Integer(3)), result);
|
assert_eq!(Ok(Value::none()), result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user