-
Notifications
You must be signed in to change notification settings - Fork 996
Closed
Description
The following code produces different results between the official Go compiler and Tinygo.
package main
const DataLen = 32
type Foo struct {
data [DataLen]byte
}
func MakeFoo(from []byte) *Foo {
foo := new(Foo)
copy(foo.data[:], from)
return foo
}
func main() {
foo := MakeFoo([]byte("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"))
println(string(foo.data[:]))
bar := MakeFoo([]byte("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"))
println(string(bar.data[:]))
}With official Go:
$ go run t.go
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
With TinyGo:
$ tinygo build -o t t.go && ./t
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
If I change the field type of Foo from array to slice, then TinyGo produces the same result as official Go.
@@ -3,11 +3,12 @@ package main
const DataLen = 32
type Foo struct {
- data [DataLen]byte
+ data []byte
}
func MakeFoo(from []byte) *Foo {
foo := new(Foo)
+ foo.data = make([]byte, DataLen)
copy(foo.data[:], from)
return foo
}I'm not sure if there's something wrong with the code I posted, or it's a bug in TinyGo. Any idea?
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working