diff --git a/schala-lang/language/src/reduced_ast.rs b/schala-lang/language/src/reduced_ast.rs index 0e66dc8..d001902 100644 --- a/schala-lang/language/src/reduced_ast.rs +++ b/schala-lang/language/src/reduced_ast.rs @@ -158,7 +158,7 @@ impl Meta { Value(qualified_name) => { let ref sym_name = match self.fqsn { Some(ref fqsn) => fqsn, - None => return Expr::ReductionError(format!("FQSN lookup for value failed")), + None => return Expr::ReductionError(format!("FQSN lookup for value A failed")), }; let FullyQualifiedSymbolName(ref v) = sym_name; let name = v.last().unwrap().name.clone(); @@ -196,7 +196,7 @@ fn reduce_lambda(params: &Vec, body: &Block, symbol_table: &SymbolT fn reduce_named_struct(fqsn: Option<&FullyQualifiedSymbolName>, name: &QualifiedName, fields: &Vec<(Rc, Meta)>, symbol_table: &SymbolTable) -> Expr { let sym_name = match fqsn { Some(fqsn) => fqsn, - None => return Expr::ReductionError(format!("FQSN lookup for value failed")), + None => return Expr::ReductionError(format!("FQSN lookup for value B failed")), }; let FullyQualifiedSymbolName(ref v) = sym_name; let ref name = v.last().unwrap().name; @@ -295,9 +295,18 @@ fn handle_symbol(symbol: Option<&Symbol>, inner_patterns: &Vec, symbol_ _ => panic!("Symbol is not a data constructor - this should've been caught in type-checking"), }); let bound_vars = inner_patterns.iter().map(|p| match p { - VarOrName(name) => { - //if this is a variable, return Some(var.clone()), else None - unimplemented!() + VarOrName(meta_name) => { + let symbol_exists = meta_name.fqsn.as_ref().and_then(|fqsn| symbol_table.lookup_by_fqsn(&fqsn)).is_some(); + if symbol_exists { + None + } else { + let QualifiedName(name_elems) = meta_name.node(); + if name_elems.len() == 1 { + Some(name_elems[0].clone()) + } else { + panic!("Bad variable name in pattern"); + } + } }, _ => None, }).collect();