cheekybits / genny

Elegant generics for Go
MIT License
1.71k stars 127 forks source link

Error while using genny command #29

Closed ammario closed 6 years ago

ammario commented 7 years ago

Input

package trie

import "github.com/cheekybits/genny/generic"

type ValueType generic.Type

//Node represents a node in the trie
type Node struct {
    branches [256]*Node
    val      generic.Type
    terminal bool
}

// Walk returns the node reached along edge c, if one exists. If node doesn't
// exist we return nil
func (n *Node) Walk(c byte) *Node {
    return n.branches[c]
}

// Terminal indicates whether n is terminal in the trie (that is, whether the path from the root to n
// represents an element in the set). For instance, if the root node is terminal, then []byte{} is in the
// trie.
func (n *Node) Terminal() bool { return n.terminal }

// Val gives the value associated with this node. It panics if n is not terminal.
func (n *Node) Val() generic.Type {
    if !n.terminal {
        panic("Val called on non-terminal node")
    }
    return n.val
}

Generation command

 genny -in node.go gen "ValueType=int"

Error

Failed to goimports the generated code: node.go:28:2: expected declaration, found 'if'
xiegeo commented 7 years ago

I think

func (n *Node) Val() generic.Type {

should be

func (n *Node) Val() ValueType {

The same for the type defination of Node.val

ammario commented 7 years ago

Thanks... Quite a ridiculous mistake on my part.