Make tag optional
This commit is contained in:
parent
2d6c9010b9
commit
bfbc1580aa
@ -202,12 +202,12 @@ fn reduce_if_expression(discriminator: &Discriminator, body: &IfExpressionBody,
|
|||||||
* x is SomeBigOldEnum(_, x, Some(t))
|
* 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::*;
|
use self::Pattern::*;
|
||||||
let tag = match symbol.spec {
|
let tag = symbol.map(|symbol| match symbol.spec {
|
||||||
SymbolSpec::DataConstructor { index, .. } => index.clone(),
|
SymbolSpec::DataConstructor { index, .. } => index.clone(),
|
||||||
_ => panic!("Symbol is not a data constructor - this should've been caught in type-checking"),
|
_ => panic!("Symbol is not a data constructor - this should've been caught in type-checking"),
|
||||||
};
|
});
|
||||||
let bound_vars = subpatterns.iter().map(|p| match p {
|
let bound_vars = subpatterns.iter().map(|p| match p {
|
||||||
Literal(PatternLiteral::VarPattern(var)) => Some(var.clone()),
|
Literal(PatternLiteral::VarPattern(var)) => Some(var.clone()),
|
||||||
_ => None,
|
_ => None,
|
||||||
@ -226,7 +226,7 @@ fn handle_symbol(symbol: &Symbol, subpatterns: &Vec<Pattern>) -> Subpattern {
|
|||||||
let subpatterns = vec![];
|
let subpatterns = vec![];
|
||||||
|
|
||||||
Subpattern {
|
Subpattern {
|
||||||
tag: Some(tag),
|
tag,
|
||||||
subpatterns,
|
subpatterns,
|
||||||
guard,
|
guard,
|
||||||
bound_vars,
|
bound_vars,
|
||||||
@ -239,7 +239,7 @@ impl Pattern {
|
|||||||
match self {
|
match self {
|
||||||
TupleStruct(name, subpatterns) => {
|
TupleStruct(name, subpatterns) => {
|
||||||
let symbol = symbol_table.lookup_by_name(name).expect(&format!("Symbol {} not found", name));
|
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 {
|
Alternative {
|
||||||
tag: s.tag,
|
tag: s.tag,
|
||||||
subpatterns: s.subpatterns,
|
subpatterns: s.subpatterns,
|
||||||
@ -310,7 +310,7 @@ impl PatternLiteral {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
VarPattern(var) => match symbol_table.lookup_by_name(var) {
|
VarPattern(var) => match symbol_table.lookup_by_name(var) {
|
||||||
Some(symbol) => handle_symbol(symbol, &vec![]),
|
Some(symbol) => handle_symbol(Some(symbol), &vec![]),
|
||||||
None => Subpattern {
|
None => Subpattern {
|
||||||
tag: None,
|
tag: None,
|
||||||
subpatterns: vec![],
|
subpatterns: vec![],
|
||||||
|
Loading…
Reference in New Issue
Block a user