-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtuple.go
More file actions
59 lines (49 loc) · 1.6 KB
/
tuple.go
File metadata and controls
59 lines (49 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package types
import (
"fmt"
"go/ast"
"strings"
"github.com/redneckbeard/thanos/bst"
)
// Tuple represents a fixed-length heterogeneous collection.
// It arises from array literals with mixed element types (e.g. [name, age]).
// Tuples cannot be used as Go slices — they must be consumed by contexts that
// understand their structure (string formatting, destructuring, etc.).
// Pointer receiver so the type is comparable (by identity) when used in == checks.
type Tuple struct {
Elements []Type
}
func NewTuple(elements []Type) *Tuple {
return &Tuple{Elements: elements}
}
func (t *Tuple) GoType() string {
parts := make([]string, len(t.Elements))
for i, el := range t.Elements {
if el != nil {
parts[i] = el.GoType()
} else {
parts[i] = "interface{}"
}
}
return fmt.Sprintf("tuple(%s)", strings.Join(parts, ", "))
}
func (t *Tuple) String() string { return t.GoType() }
func (t *Tuple) Equals(t2 Type) bool { return false }
func (t *Tuple) IsComposite() bool { return false }
func (t *Tuple) IsMultiple() bool { return false }
func (t *Tuple) ClassName() string { return "Tuple" }
func (t *Tuple) HasMethod(m string) bool {
return false
}
func (t *Tuple) MethodReturnType(m string, b Type, args []Type) (Type, error) {
return nil, fmt.Errorf("Tuple does not support method '%s'", m)
}
func (t *Tuple) GetMethodSpec(m string) (MethodSpec, bool) {
return MethodSpec{}, false
}
func (t *Tuple) BlockArgTypes(m string, args []Type) []Type {
return nil
}
func (t *Tuple) TransformAST(m string, rcvr ast.Expr, args []TypeExpr, blk *Block, it bst.IdentTracker) Transform {
return Transform{}
}