Allow explicit returns of built-in status codes.

This commit is contained in:
Nigel Tao committed 2017-10-06 17:34:58 +11:00
1 parent 2e883fcc23
commit 010c4db54f
7 files changed
+43 -12

No files matched your search

+11 -4
View File
@@ -120,10 +120,17 @@ func (q *checker) tcheckStatement(n *a.Node) error {
case a.KReturn:
n := n.Return()
if nk := n.Keyword(); nk != 0 {
if s, ok := q.c.statuses[n.Message()]; !ok {
return fmt.Errorf("check: no error or status with message %q",
trimQuotes(n.Message().String(q.tm)))
} else if sk := s.Status.Keyword(); nk != sk {
sk := t.ID(0)
if s, ok := q.c.statuses[n.Message()]; ok {
sk = s.Status.Keyword()
} else {
msg := trimQuotes(n.Message().String(q.tm))
sk, ok = builtInStatuses[msg]
if !ok {
return fmt.Errorf("check: no error or status with message %q", msg)
}
}
if nk != sk {
return fmt.Errorf("check: return statement says %q but declaration says %q",
nk.String(q.tm), sk.String(q.tm))
}