fix: handle type declaration inside function
This commit is contained in:
committed by
Traefiker Bot
parent
35e645c690
commit
0f46cd5efb
12
_test/fun9.go
Normal file
12
_test/fun9.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package main
|
||||
|
||||
type T uint
|
||||
|
||||
func main() {
|
||||
type myint int
|
||||
var i = myint(1)
|
||||
println(i)
|
||||
}
|
||||
|
||||
// Output:
|
||||
// 1
|
||||
@@ -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:
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user