Skip to content

Commit

Permalink
Fix match error panic
Browse files Browse the repository at this point in the history
  • Loading branch information
tsandall committed Oct 30, 2017
1 parent cc2e0b1 commit e4fa1e2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
20 changes: 12 additions & 8 deletions ast/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -630,18 +630,22 @@ func unifies(a, b types.Type) bool {
return false
}

var unified bool

if anyA, ok := a.(types.Any); ok {
unified = unifiesAny(anyA, b)
anyA, ok1 := a.(types.Any)
if ok1 {
if unifiesAny(anyA, b) {
return true
}
}

if anyB, ok := b.(types.Any); ok {
unified = unified || unifiesAny(anyB, a)
anyB, ok2 := b.(types.Any)
if ok2 {
if unifiesAny(anyB, a) {
return true
}
}

if unified {
return true
if ok1 || ok2 {
return false
}

switch a := a.(type) {
Expand Down
1 change: 1 addition & 0 deletions ast/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,7 @@ func TestCheckMatchErrors(t *testing.T) {
{"object-nested", `{ {"a": 1, "b": "2"} = {"a": 1, "b": 2} }`},
{"object-nested-2", `{ {"a": 1} = {"a": 1, "b": "2"} }`},
{"set", "{{1,2,3} = null}"},
{"any", `{x = ["str", 1]; x[_] = null}`},
}
for _, tc := range tests {
test.Subtest(t, tc.note, func(t *testing.T) {
Expand Down

0 comments on commit e4fa1e2

Please sign in to comment.