lang: make "return a slice" return a slice of this

This commit is contained in:
Nigel Tao committed 2023-06-13 22:38:29 +10:00
1 parent 66723c6706
commit 43beae1d3d
3 files changed
+31 -12

No files matched your search

+14
View File
@@ -240,6 +240,20 @@ func (q *checker) tcheckStatement(n *a.Node) error {
return fmt.Errorf("check: cannot return %q (of type %q) as type %q",
value.Str(q.tm), rTyp.Str(q.tm), lTyp.Str(q.tm))
}
if rTyp.IsEitherSliceType() {
ok := false
if value.Operator() != t.IDDotDot {
// No-op.
} else if lhs := value.LHS().AsExpr(); lhs.Operator() != t.IDDot {
// No-op.
} else if llhs := lhs.LHS().AsExpr(); true {
ok = (llhs.Operator() == 0) && (llhs.Ident() == t.IDThis)
}
if !ok {
return fmt.Errorf("check: cannot return %q, need something of the form this.etc[i .. j]",
value.Str(q.tm))
}
}
case a.KVar:
n := n.AsVar()