Skip to content

Commit 8df930d

Browse files
committed
make Expr sum type
1 parent 84056cc commit 8df930d

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

ast/node.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type ExCommand interface {
2525
// Expr is the interface for expression.
2626
type Expr interface {
2727
Node
28+
exprNode()
2829
}
2930

3031
// File node represents a Vim script source file.
@@ -480,7 +481,7 @@ type CurlyName struct {
480481
func (c *CurlyName) Pos() Pos { return c.CurlyName }
481482

482483
type CurlyNamePart interface {
483-
Node
484+
Expr
484485
IsCurlyExpr() bool
485486
}
486487

@@ -522,3 +523,22 @@ type LambdaExpr struct {
522523
}
523524

524525
func (i *LambdaExpr) Pos() Pos { return i.Lcurlybrace }
526+
527+
// exprNode() ensures that only expression nodes can be assigned to an Expr.
528+
//
529+
func (*TernaryExpr) exprNode() {}
530+
func (*BinaryExpr) exprNode() {}
531+
func (*UnaryExpr) exprNode() {}
532+
func (*SubscriptExpr) exprNode() {}
533+
func (*SliceExpr) exprNode() {}
534+
func (*CallExpr) exprNode() {}
535+
func (*DotExpr) exprNode() {}
536+
func (*BasicLit) exprNode() {}
537+
func (*List) exprNode() {}
538+
func (*Dict) exprNode() {}
539+
func (*KeyValue) exprNode() {}
540+
func (*CurlyName) exprNode() {}
541+
func (*CurlyNameLit) exprNode() {}
542+
func (*CurlyNameExpr) exprNode() {}
543+
func (*Ident) exprNode() {}
544+
func (*LambdaExpr) exprNode() {}

0 commit comments

Comments
 (0)