diff --git a/_test/fun9.go b/_test/fun9.go new file mode 100644 index 000000000..8bab6d5a3 --- /dev/null +++ b/_test/fun9.go @@ -0,0 +1,12 @@ +package main + +type T uint + +func main() { + type myint int + var i = myint(1) + println(i) +} + +// Output: +// 1 diff --git a/interp/cfg.go b/interp/cfg.go index 1d8eb6d22..be1e43e9e 100644 --- a/interp/cfg.go +++ b/interp/cfg.go @@ -309,7 +309,25 @@ func (interp *Interpreter) cfg(root *node) ([]*node, error) { return false case typeSpec: - // processing already done in GTA pass + // processing already done in GTA pass for global types, only parses inlined types + if sc.def != nil { + typeName := n.child[0].ident + var typ *itype + if typ, err = nodeType(interp, sc, n.child[1]); err != nil { + return false + } + if typ.incomplete { + err = n.cfgErrorf("invalid type declaration") + return false + } + if n.child[1].kind == identExpr { + n.typ = &itype{cat: aliasT, val: typ, name: typeName} + } else { + n.typ = typ + n.typ.name = typeName + } + sc.sym[typeName] = &symbol{kind: typeSym, typ: n.typ} + } return false case arrayType, basicLit, chanType, funcType, mapType, structType: diff --git a/interp/gta.go b/interp/gta.go index 6a24c2f01..25f76432d 100644 --- a/interp/gta.go +++ b/interp/gta.go @@ -174,7 +174,7 @@ func (interp *Interpreter) gta(root *node, rpath string) ([]*node, error) { n.typ.name = typeName n.typ.path = rpath } - // Type may already be declared for a receiver in a method function + // Type may be already declared for a receiver in a method function if sc.sym[typeName] == nil { sc.sym[typeName] = &symbol{kind: typeSym} } else {