fix: compute type of slice expression globally
This commit is contained in:
committed by
Traefiker Bot
parent
1cf327bd7d
commit
7d19108f01
11
_test/var9.go
Normal file
11
_test/var9.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package main
|
||||
|
||||
var a = "sdofjsdfj"
|
||||
var z = a[0:2]
|
||||
|
||||
func main() {
|
||||
println(z)
|
||||
}
|
||||
|
||||
// Output:
|
||||
// sd
|
||||
@@ -1309,18 +1309,8 @@ func (interp *Interpreter) cfg(root *node) ([]*node, error) {
|
||||
|
||||
case sliceExpr:
|
||||
wireChild(n)
|
||||
ctyp := n.child[0].typ
|
||||
if ctyp.cat == ptrT {
|
||||
ctyp = ctyp.val
|
||||
}
|
||||
if ctyp.size != 0 {
|
||||
// Create a slice type from an array type
|
||||
n.typ = &itype{}
|
||||
*n.typ = *ctyp
|
||||
n.typ.size = 0
|
||||
n.typ.rtype = nil
|
||||
} else {
|
||||
n.typ = ctyp
|
||||
if n.typ, err = nodeType(interp, sc, n); err != nil {
|
||||
return
|
||||
}
|
||||
n.findex = sc.add(n.typ)
|
||||
|
||||
|
||||
@@ -486,6 +486,18 @@ func nodeType(interp *Interpreter, sc *scope, n *node) (*itype, error) {
|
||||
}
|
||||
}
|
||||
|
||||
case sliceExpr:
|
||||
t, err = nodeType(interp, sc, n.child[0])
|
||||
if t.cat == ptrT {
|
||||
t = t.val
|
||||
}
|
||||
if err == nil && t.size != 0 {
|
||||
t1 := *t
|
||||
t1.size = 0
|
||||
t1.rtype = nil
|
||||
t = &t1
|
||||
}
|
||||
|
||||
case structType:
|
||||
t.cat = structT
|
||||
var incomplete bool
|
||||
|
||||
Reference in New Issue
Block a user