Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
afsalthaj committed Dec 12, 2024
1 parent 4ffe0c5 commit a7924aa
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 56 deletions.
98 changes: 44 additions & 54 deletions golem-rib/src/interpreter/interpreter_stack_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,65 +122,55 @@ impl RibInterpreterStackValue {

pub fn unwrap(&self) -> Option<ValueAndType> {
match self {
RibInterpreterStackValue::Val(val) => {
match (val.value.clone(), val.typ.clone()) {
(Value::Option(option), AnalysedType::Option(option_type)) => {
Some(ValueAndType {
value: option.unwrap().deref().clone(),
typ: option_type.inner.deref().clone(),
})
}

(Value::Result(result), AnalysedType::Result(result_type)) => match result {
Ok(Some(ok)) => Some(ValueAndType {
value: ok.deref().clone(),
typ: result_type.ok.unwrap().deref().clone(),
}),
RibInterpreterStackValue::Val(val) => match (val.value.clone(), val.typ.clone()) {
(Value::Option(Some(option)), AnalysedType::Option(option_type)) => {
let inner_value = option.deref().clone();
let inner_type = option_type.inner.deref().clone();
Some(ValueAndType {
value: inner_value,
typ: inner_type,
})
}

Err(Some(err)) => Some(ValueAndType {
value: err.deref().clone(),
typ: result_type.err.unwrap().deref().clone(),
}),
_ => None,
},
(Value::Result(Ok(Some(ok))), AnalysedType::Result(result_type)) => {
let ok_value = ok.deref().clone();
let ok_type = result_type.ok.as_ref()?.deref().clone();
Some(ValueAndType {
value: ok_value,
typ: ok_type,
})
}

(
Value::Variant {
case_value,
case_idx,
},
AnalysedType::Variant(variant_type),
) => Some(ValueAndType {
value: case_value.unwrap().deref().clone(),
typ: variant_type.cases[case_idx as usize].clone().typ.unwrap(),
}),
(Value::Result(Err(Some(err))), AnalysedType::Result(result_type)) => {
let err_value = err.deref().clone();
let err_type = result_type.err.as_ref()?.deref().clone();
Some(ValueAndType {
value: err_value,
typ: err_type,
})
}

_ => None,
(
Value::Variant {
case_value: Some(case_value),
case_idx,
},
AnalysedType::Variant(variant_type),
) => {
let case_type = variant_type
.cases
.get(case_idx as usize)?
.typ
.as_ref()?
.clone();
Some(ValueAndType {
value: case_value.deref().clone(),
typ: case_type,
})
}

// match val.value {
// Va:Option(option) => option
// .value
// .as_deref()
// .and_then(|x| x.type_annotated_value.clone()),
// TypeAnnotatedValue::Result(result) => {
// let result = match &result.result_value {
// Some(ResultValue::OkValue(ok)) => Some(ok.clone()),
// Some(ResultValue::ErrorValue(err)) => Some(err.clone()),
// None => None,
// };
//
// // GRPC wrapper
// result.and_then(|x| x.type_annotated_value)
// }
//
// TypeAnnotatedValue::Variant(variant) => variant
// .case_value
// .as_deref()
// .and_then(|x| x.type_annotated_value.clone()),
// _ => None,
// }
}
_ => None,
},
RibInterpreterStackValue::Unit => None,
RibInterpreterStackValue::Iterator(_) => None,
RibInterpreterStackValue::Sink(_, _) => None,
Expand Down
4 changes: 2 additions & 2 deletions golem-rib/src/interpreter/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ impl InterpreterStack {
.iter()
.position(|case| case.name == variant_name)
.unwrap() as u32; // TODO: return error
let case_value = optional_variant_value.map(|value| Box::new(value));
let case_value = optional_variant_value.map(Box::new);
self.push_val(ValueAndType::new(
Value::Variant {
case_idx,
Expand All @@ -212,7 +212,7 @@ impl InterpreterStack {
self.push_val(ValueAndType::new(
Value::Enum(idx),
AnalysedType::Enum(TypeEnum {
cases: cases.into_iter().map(|x| x.into()).collect(),
cases: cases.into_iter().collect(),
}),
));
}
Expand Down

0 comments on commit a7924aa

Please sign in to comment.