Skip to content

Commit

Permalink
go/constant: improved fatal error messages
Browse files Browse the repository at this point in the history
Fixes #17812.

Change-Id: I08202165dd3f72ae04420e7b6129b8b689e74f5c
Reviewed-on: https://go-review.googlesource.com/32870
Reviewed-by: Alan Donovan <[email protected]>
  • Loading branch information
griesemer committed Nov 7, 2016
1 parent 9d139ac commit 4eb9832
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/go/constant/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,8 @@ Error:

func ord(x Value) int {
switch x.(type) {
default:
return -1 // force invalid value into "x position" in match
case unknownVal:
return 0
case boolVal, stringVal:
Expand All @@ -862,8 +864,6 @@ func ord(x Value) int {
return 5
case complexVal:
return 6
default:
panic("unreachable")
}
}

Expand All @@ -880,9 +880,6 @@ func match(x, y Value) (_, _ Value) {
// ord(x) <= ord(y)

switch x := x.(type) {
case unknownVal:
return x, x

case boolVal, stringVal, complexVal:
return x, y

Expand Down Expand Up @@ -921,6 +918,7 @@ func match(x, y Value) (_, _ Value) {
case complexVal:
return vtoc(x), y
}

case floatVal:
switch y := y.(type) {
case floatVal:
Expand All @@ -930,7 +928,7 @@ func match(x, y Value) (_, _ Value) {
}
}

panic("unreachable")
return x, x // force unknown and invalid values into "x position" in callers of match
}

// BinaryOp returns the result of the binary expression x op y.
Expand Down Expand Up @@ -1171,7 +1169,7 @@ func cmpZero(x int, op token.Token) bool {
case token.GEQ:
return x >= 0
}
panic("unreachable")
panic(fmt.Sprintf("invalid comparison %v %s 0", x, op))
}

// Compare returns the result of the comparison x op y.
Expand Down

0 comments on commit 4eb9832

Please sign in to comment.