compiler: allow to convert string constants to []byte

Also load constant directly into stack, not by name.
This commit is contained in:
Evgenii Stratonikov 2020-01-27 13:37:33 +03:00
parent 1cfad9ccb8
commit d65d6ab08d
2 changed files with 30 additions and 5 deletions

View file

@ -54,3 +54,28 @@ func TestByteConversionDirectlyInFunctionCall(t *testing.T) {
`
eval(t, src, []byte("foo"))
}
func TestByteConversionOfConstant(t *testing.T) {
src := `
package foo
const foo = "foo"
func Main() []byte {
b := []byte(foo)
return b
}
`
eval(t, src, []byte("foo"))
}
func TestByteConversionOfVariable(t *testing.T) {
src := `
package foo
func Main() []byte {
a := "fo"
a = a + "o"
b := []byte(a)
return b
}
`
eval(t, src, []byte("foo"))
}