Make tag optional

This commit is contained in:
greg 2018-10-30 23:36:55 -07:00
parent 2d6c9010b9
commit bfbc1580aa

View File

@ -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<Pattern>) -> Subpattern {
fn handle_symbol(symbol: Option<&Symbol>, subpatterns: &Vec<Pattern>) -> 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<Pattern>) -> 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![],