Skip to content

Commit

Permalink
interp: added sliceExpr and starExpr
Browse files Browse the repository at this point in the history
Type check was failing for expression such as: `&(*tree)[node:][0]`, as in

```go
tree, _ := huffmanTreePool.Get().(*[]huffmanTree)
...

initHuffmanTree(&(*tree)[node:][0], histogram[l], -1, int16(l))
```

see https://github.com/andybalholm/brotli/blob/c3da72aa01ed78f164593b9624fd91d25082d2d2/brotli_bit_stream.go#L469
  • Loading branch information
rsteube committed Oct 21, 2020
1 parent 22c63b2 commit d7ede8e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
22 changes: 22 additions & 0 deletions _test/addr1.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package main

import "fmt"

type T struct {
A int
B int
}

func main() {
a := &[]T{
{1, 2},
{3, 4},
}
fmt.Println("a:", a)
x := &(*a)[1:][0]
fmt.Println("x:", x)
}

// Output:
// a: &[{1 2} {3 4}]
// x: &{3 4}
5 changes: 4 additions & 1 deletion interp/typecheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ func (check typecheck) addressExpr(n *node) error {
case selectorExpr:
c0 = c0.child[1]
continue
case indexExpr:
case starExpr:
c0 = c0.child[0]
continue
case indexExpr, sliceExpr:
c := c0.child[0]
if isArray(c.typ) || isMap(c.typ) {
c0 = c
Expand Down

0 comments on commit d7ede8e

Please sign in to comment.