-
Notifications
You must be signed in to change notification settings - Fork 364
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
interp: take into account embedded property of struct field
The trick is that in reflect, the field is called Anonymous, which is actually a different notion in the Go spec/vocable. n.b. only works for non-recursive types for now. Fixes #781
- Loading branch information
Showing
3 changed files
with
54 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
) | ||
|
||
type A struct { | ||
IA InnerA | ||
} | ||
|
||
type InnerA struct { | ||
Timestamp int64 | ||
} | ||
|
||
func main() { | ||
a := &A{} | ||
b, _ := json.Marshal(a) | ||
fmt.Println(string(b)) | ||
} | ||
|
||
// Output: | ||
// {"IA":{"Timestamp":0}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
) | ||
|
||
type A struct { | ||
InnerA | ||
} | ||
|
||
type InnerA struct { | ||
Timestamp int64 | ||
} | ||
|
||
func main() { | ||
a := &A{} | ||
b, _ := json.Marshal(a) | ||
fmt.Println(string(b)) | ||
} | ||
|
||
// Output: | ||
// {"Timestamp":0} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters