-
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: fix use of function as field of a recursive struct.
The logic of patching reflect struct representation has been fixed in presence of function fields and to better handle indirect recursivity (struct recursive through nested struct). Fixes #1519.
- Loading branch information
Showing
4 changed files
with
92 additions
and
19 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,16 @@ | ||
package main | ||
|
||
type F func(a *A) | ||
|
||
type A struct { | ||
Name string | ||
F | ||
} | ||
|
||
func main() { | ||
a := &A{"Test", func(a *A) { println("in f", a.Name) }} | ||
a.F(a) | ||
} | ||
|
||
// Output: | ||
// in f Test |
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,27 @@ | ||
package main | ||
|
||
type F func(a *A) | ||
|
||
type A struct { | ||
B string | ||
D | ||
f F | ||
} | ||
|
||
type D struct { | ||
*A | ||
E *A | ||
} | ||
|
||
func f1(a *A) { println("in f1", a.B) } | ||
|
||
func main() { | ||
a := &A{B: "b", f: f1} | ||
a.D = D{E: a} | ||
println(a.D.E.B) | ||
a.f(a) | ||
} | ||
|
||
// Output: | ||
// b | ||
// in f1 b |
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,25 @@ | ||
package main | ||
|
||
type F func(a *A) | ||
|
||
type A struct { | ||
B string | ||
D | ||
} | ||
|
||
type D struct { | ||
*A | ||
E *A | ||
f F | ||
} | ||
|
||
func f1(a *A) { println("in f1", a.B) } | ||
|
||
func main() { | ||
a := &A{B: "b"} | ||
a.D = D{f: f1} | ||
a.f(a) | ||
} | ||
|
||
// Output: | ||
// in f1 b |
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