Analyze match expression default cases
This commit is contained in:
parent
493731f6d0
commit
bd819c2571
@ -33,6 +33,16 @@ U: (| Int F64)
|
|||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMatchDefault (test *testing.T) {
|
||||||
|
testString (test,
|
||||||
|
`
|
||||||
|
U: (| Int F64)
|
||||||
|
[isInt u:U]:Bool = match u
|
||||||
|
| u:Int [return true]
|
||||||
|
* false
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
func TestMatchUnionUnderComplete (test *testing.T) {
|
func TestMatchUnionUnderComplete (test *testing.T) {
|
||||||
testString (test,
|
testString (test,
|
||||||
`
|
`
|
||||||
|
@ -759,7 +759,21 @@ func (this *Tree) analyzeMatch (
|
|||||||
match.CaseMap[hash] = cas
|
match.CaseMap[hash] = cas
|
||||||
}
|
}
|
||||||
|
|
||||||
if into != nil && len(match.Cases) < len(rawUnion.Allowed) {
|
if match.Default != nil {
|
||||||
|
this.pushScope(match.Default)
|
||||||
|
expression, err := this.analyzeExpression (
|
||||||
|
into, mode,
|
||||||
|
match.Default.Expression)
|
||||||
|
this.popScope()
|
||||||
|
|
||||||
|
if err != nil { return nil, err }
|
||||||
|
match.Default.Expression = expression
|
||||||
|
}
|
||||||
|
|
||||||
|
allCasesCovered :=
|
||||||
|
len(match.Cases) == len(rawUnion.Allowed) ||
|
||||||
|
match.Default != nil
|
||||||
|
if into != nil && !allCasesCovered {
|
||||||
return nil, errors.Errorf (
|
return nil, errors.Errorf (
|
||||||
match.Position(),
|
match.Position(),
|
||||||
"match does not cover all types within %v",
|
"match does not cover all types within %v",
|
||||||
@ -772,7 +786,7 @@ func (this *Tree) analyzeMatch (
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *Tree) assembleMatchMap (match *entity.Match) (*entity.Match, error) {
|
func (this *Tree) assembleMatchMap (match *entity.Match) (*entity.Match, error) {
|
||||||
match.CaseMap = make(map[entity.Hash] *entity.Case)
|
match.CaseMap = make(map[entity.Hash] *entity.MatchCase)
|
||||||
match.CaseOrder = make([]entity.Hash, len(match.Cases))
|
match.CaseOrder = make([]entity.Hash, len(match.Cases))
|
||||||
for index, cas := range match.Cases {
|
for index, cas := range match.Cases {
|
||||||
hash := cas.Declaration.Ty.Hash()
|
hash := cas.Declaration.Ty.Hash()
|
||||||
|
Loading…
Reference in New Issue
Block a user