-
Notifications
You must be signed in to change notification settings - Fork 358
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: handle use of functions in struct fields
- Loading branch information
Showing
6 changed files
with
126 additions
and
17 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,39 @@ | ||
package main | ||
|
||
type T0 struct { | ||
name string | ||
} | ||
|
||
type lookupFunc func(s string) T0 | ||
|
||
type T1 struct { | ||
name string | ||
info lookupFunc | ||
} | ||
|
||
func (t T0) F1() bool { println("in F1"); return true } | ||
|
||
type T2 struct { | ||
t1 T1 | ||
} | ||
|
||
func (t2 *T2) f() { | ||
info := t2.t1.info("foo") | ||
println(info.F1()) | ||
} | ||
|
||
var t0 = T0{"t0"} | ||
|
||
func main() { | ||
t := &T2{T1{ | ||
"bar", func(s string) T0 { return t0 }, | ||
}} | ||
|
||
println("hello") | ||
println(t.t1.info("foo").F1()) | ||
} | ||
|
||
// Output: | ||
// hello | ||
// in F1 | ||
// true |
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,34 @@ | ||
package main | ||
|
||
type T0 struct { | ||
name string | ||
} | ||
|
||
type lookupFunc func(s string) T0 | ||
|
||
type T1 struct { | ||
name string | ||
info lookupFunc | ||
} | ||
|
||
func (t T0) F1() bool { println("in F1"); return true } | ||
|
||
var t0 = T0{"t0"} | ||
|
||
func look(s string) T0 { println("in look"); return t0 } | ||
|
||
var table = []*T1{{ | ||
name: "bar", | ||
info: look, | ||
}, | ||
} | ||
|
||
func main() { | ||
info := table[0].info | ||
println(info("foo").F1()) | ||
} | ||
|
||
// Output: | ||
// in look | ||
// in F1 | ||
// true |
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
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
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
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