feat: support func fields in literal struct (#103)

* test: make select2 deterministic
This commit is contained in:
Marc Vertes
2019-02-22 15:44:36 +01:00
committed by Ludovic Fernandez
parent 99fe292e66
commit 2ef6e459e3
4 changed files with 23 additions and 13 deletions

View File

@@ -15,17 +15,21 @@ func main() {
case c2 <- toSend:
a++
}
c1 <- "done"
}()
select {
case msg1 := <-c1:
fmt.Println("received from c1:", msg1)
case msg2 := <-c2:
fmt.Println("received from c2:", msg2)
for i := 0; i < 2; i++ {
select {
case msg1 := <-c1:
fmt.Println("received from c1:", msg1)
case msg2 := <-c2:
fmt.Println("received from c2:", msg2)
}
}
fmt.Println("Bye", a)
}
// Output:
// received from c2: hello
// received from c1: done
// Bye 1

View File

@@ -144,8 +144,6 @@ func f() string {
}
func TestEvalStruct1(t *testing.T) {
t.Skip("not yet implemented")
log.SetFlags(log.Lshortfile)
i := interp.New(interp.Opt{})
evalCheck(t, i, `
type Fromage struct {

View File

@@ -5641,13 +5641,16 @@ func main() {
case c2 <- toSend:
a++
}
c1 <- "done"
}()
select {
case msg1 := <-c1:
fmt.Println("received from c1:", msg1)
case msg2 := <-c2:
fmt.Println("received from c2:", msg2)
for i := 0; i < 2; i++ {
select {
case msg1 := <-c1:
fmt.Println("received from c1:", msg1)
case msg2 := <-c2:
fmt.Println("received from c2:", msg2)
}
}
fmt.Println("Bye", a)
}
@@ -5661,6 +5664,7 @@ func main() {
// Output:
// received from c2: hello
// received from c1: done
// Bye 1
}

View File

@@ -1031,7 +1031,11 @@ func compositeLit(n *Node) {
values := make([]func(*Frame) reflect.Value, len(child))
for i, c := range child {
convertLiteralValue(c, n.typ.field[i].typ.TypeOf())
values[i] = genValue(c)
if c.typ.cat == FuncT {
values[i] = genNodeWrapper(c)
} else {
values[i] = genValue(c)
}
}
n.exec = func(f *Frame) Builtin {