diff --git a/huia-compiler/src/context.rs b/huia-compiler/src/context.rs index 1c8a215..3d5a6e9 100644 --- a/huia-compiler/src/context.rs +++ b/huia-compiler/src/context.rs @@ -76,7 +76,7 @@ impl Context { .any(|t| t.name() == Some(name.clone()) && !t.is_unresolved()) { let message = format!("Type {} redefined", self.get_string(name).unwrap()); - self.compile_error(&message, location.clone(), ErrorKind::TypeRedefined) + self.compile_error(&message, location.clone(), ErrorKind::TypeRedefined); } let idx = self.types.len(); @@ -219,7 +219,7 @@ impl Context { // This can theoretically return another type reference, so we still // have to do a full type-check. for (i, ty) in self.types.iter().enumerate() { - if ty.name().is_some() && &ty.name().unwrap() == name { + if ty.name() == Some(name.clone()) { return i.into(); } } diff --git a/huia-compiler/src/function.rs b/huia-compiler/src/function.rs index e6b41ac..4585bcc 100644 --- a/huia-compiler/src/function.rs +++ b/huia-compiler/src/function.rs @@ -1,6 +1,7 @@ use crate::block::BlockIdx; use crate::stable::StringIdx; use crate::ty::TyIdx; +use std::collections::BTreeMap; #[derive(Debug)] pub struct Function { @@ -29,12 +30,16 @@ impl Function { #[derive(Debug)] pub struct Clause { - arguments: Vec<(StringIdx, TyIdx)>, + arguments: BTreeMap, body: BlockIdx, } impl Clause { pub fn new(arguments: Vec<(StringIdx, TyIdx)>, body: BlockIdx) -> Clause { + let arguments = arguments.iter().fold(BTreeMap::new(), |mut args, (k, v)| { + args.insert(k.clone(), v.clone()); + args + }); Clause { arguments, body } } }