diff --git a/schala-lang/language/src/reduced_ast.rs b/schala-lang/language/src/reduced_ast.rs index 8189ae6..1bfdef0 100644 --- a/schala-lang/language/src/reduced_ast.rs +++ b/schala-lang/language/src/reduced_ast.rs @@ -202,12 +202,12 @@ fn reduce_if_expression(discriminator: &Discriminator, body: &IfExpressionBody, * x is SomeBigOldEnum(_, x, Some(t)) */ -fn handle_symbol(symbol: &Symbol, subpatterns: &Vec) -> Subpattern { +fn handle_symbol(symbol: Option<&Symbol>, subpatterns: &Vec) -> Subpattern { use self::Pattern::*; - let tag = match symbol.spec { + let tag = symbol.map(|symbol| match symbol.spec { SymbolSpec::DataConstructor { index, .. } => index.clone(), _ => panic!("Symbol is not a data constructor - this should've been caught in type-checking"), - }; + }); let bound_vars = subpatterns.iter().map(|p| match p { Literal(PatternLiteral::VarPattern(var)) => Some(var.clone()), _ => None, @@ -226,7 +226,7 @@ fn handle_symbol(symbol: &Symbol, subpatterns: &Vec) -> Subpattern { let subpatterns = vec![]; Subpattern { - tag: Some(tag), + tag, subpatterns, guard, bound_vars, @@ -239,7 +239,7 @@ impl Pattern { match self { TupleStruct(name, subpatterns) => { let symbol = symbol_table.lookup_by_name(name).expect(&format!("Symbol {} not found", name)); - let s = handle_symbol(symbol, subpatterns); + let s = handle_symbol(Some(symbol), subpatterns); Alternative { tag: s.tag, subpatterns: s.subpatterns, @@ -310,7 +310,7 @@ impl PatternLiteral { } }, VarPattern(var) => match symbol_table.lookup_by_name(var) { - Some(symbol) => handle_symbol(symbol, &vec![]), + Some(symbol) => handle_symbol(Some(symbol), &vec![]), None => Subpattern { tag: None, subpatterns: vec![],