Skip to content

Commit

Permalink
fix: actually add the error type to prelude (#672)
Browse files Browse the repository at this point in the history
  • Loading branch information
ss2165 authored Nov 9, 2023
1 parent cb239e0 commit b256c2b
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/extension/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ lazy_static! {
)
.unwrap();
prelude
.add_type(
ERROR_TYPE_NAME,
vec![],
"Simple opaque error type.".into(),
TypeDefBound::Explicit(TypeBound::Eq),
)
.unwrap();
prelude
};
/// An extension registry containing only the prelude
pub static ref PRELUDE_REGISTRY: ExtensionRegistry = [PRELUDE_DEF.to_owned()].into();
Expand Down Expand Up @@ -120,11 +128,14 @@ pub fn new_array_op(element_ty: Type, size: u64) -> LeafOp {

/// Unspecified opaque error type.
pub const ERROR_TYPE: Type = Type::new_extension(CustomType::new_simple(
smol_str::SmolStr::new_inline("error"),
ERROR_TYPE_NAME,
PRELUDE_ID,
TypeBound::Eq,
));

/// The string name of the error type.
pub const ERROR_TYPE_NAME: SmolStr = SmolStr::new_inline("error");

#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
/// Structure for holding constant usize values.
pub struct ConstUsize(u64);
Expand Down Expand Up @@ -183,4 +194,17 @@ mod test {

b.finish_prelude_hugr_with_outputs(out.outputs()).unwrap();
}

#[test]
/// Test building a HUGR involving a new_array operation.
fn test_error_type() {
let ext_def = PRELUDE
.get_type(&ERROR_TYPE_NAME)
.unwrap()
.instantiate([])
.unwrap();

let ext_type = Type::new_extension(ext_def);
assert_eq!(ext_type, ERROR_TYPE);
}
}

0 comments on commit b256c2b

Please sign in to comment.