forked from TrueCloudLab/neoneo-go
compiler: allow to omit types for nested slices
This commit is contained in:
parent
53f2e130c0
commit
5a615d8178
2 changed files with 26 additions and 9 deletions
|
@ -594,15 +594,11 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor {
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
case *ast.CompositeLit:
|
case *ast.CompositeLit:
|
||||||
typ := c.typeOf(n.Type).Underlying()
|
switch typ := c.typeOf(n).Underlying().(type) {
|
||||||
switch n.Type.(type) {
|
|
||||||
case *ast.Ident, *ast.SelectorExpr, *ast.MapType:
|
|
||||||
switch typ.(type) {
|
|
||||||
case *types.Struct:
|
case *types.Struct:
|
||||||
c.convertStruct(n)
|
c.convertStruct(n)
|
||||||
case *types.Map:
|
case *types.Map:
|
||||||
c.convertMap(n)
|
c.convertMap(n)
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
ln := len(n.Elts)
|
ln := len(n.Elts)
|
||||||
// ByteArrays needs a different approach than normal arrays.
|
// ByteArrays needs a different approach than normal arrays.
|
||||||
|
|
|
@ -222,6 +222,27 @@ var sliceTestCases = []testCase{
|
||||||
}`,
|
}`,
|
||||||
big.NewInt(42),
|
big.NewInt(42),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"nested slice omitted type (slice)",
|
||||||
|
`package foo
|
||||||
|
func Main() int {
|
||||||
|
a := [][]int{{1, 2}, {3, 4}}
|
||||||
|
a[1][0] = 42
|
||||||
|
return a[1][0]
|
||||||
|
}`,
|
||||||
|
big.NewInt(42),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"nested slice omitted type (struct)",
|
||||||
|
`package foo
|
||||||
|
type pair struct { a, b int }
|
||||||
|
func Main() int {
|
||||||
|
a := []pair{{a: 1, b: 2}, {a: 3, b: 4}}
|
||||||
|
a[1].a = 42
|
||||||
|
return a[1].a
|
||||||
|
}`,
|
||||||
|
big.NewInt(42),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSliceOperations(t *testing.T) {
|
func TestSliceOperations(t *testing.T) {
|
||||||
|
|
Loading…
Reference in a new issue