summaryrefslogtreecommitdiff
path: root/vendor/github.com/hashicorp/hil/ast/variable_access.go
blob: 4c1362d75315cf1e506bd01622d38c3f15815148 (plain)
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
package ast

import (
	"fmt"
)

// VariableAccess represents a variable access.
type VariableAccess struct {
	Name string
	Posx Pos
}

func (n *VariableAccess) Accept(v Visitor) Node {
	return v(n)
}

func (n *VariableAccess) Pos() Pos {
	return n.Posx
}

func (n *VariableAccess) GoString() string {
	return fmt.Sprintf("*%#v", *n)
}

func (n *VariableAccess) String() string {
	return fmt.Sprintf("Variable(%s)", n.Name)
}

func (n *VariableAccess) Type(s Scope) (Type, error) {
	v, ok := s.LookupVar(n.Name)
	if !ok {
		return TypeInvalid, fmt.Errorf("unknown variable: %s", n.Name)
	}

	return v.Type, nil
}