At CFG, in pre-order processing, determine the correct type of CompositeLitExpr from its first child (if it's a type) or from the ancestor node. Make sure The type is propagated to children so the algorithm works recursively. Fix also the isType() method to handle case of imported types, either from source or binary packages.
32 lines
436 B
Go
32 lines
436 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"sort"
|
|
)
|
|
|
|
type Foo struct {
|
|
Name string
|
|
}
|
|
|
|
func main() {
|
|
m := map[string][]Foo{
|
|
"hello": []Foo{{"foo"}, {"bar"}},
|
|
"world": []Foo{{"truc"}, {"machin"}},
|
|
}
|
|
|
|
var content []string
|
|
|
|
for key, values := range m {
|
|
for _, value := range values {
|
|
content = append(content, key+value.Name)
|
|
}
|
|
}
|
|
|
|
sort.Strings(content)
|
|
fmt.Println(content)
|
|
}
|
|
|
|
// Output:
|
|
// [hellobar hellofoo worldmachin worldtruc]
|