File tree 2 files changed +31
-3
lines changed
2 files changed +31
-3
lines changed Original file line number Diff line number Diff line change @@ -1613,6 +1613,32 @@ func TestIssue271(t *testing.T) {
1613
1613
require .Equal (t , 1.0 , output )
1614
1614
}
1615
1615
1616
+ type Issue346Array []Issue346Type
1617
+
1618
+ type Issue346Type struct {
1619
+ Bar string
1620
+ }
1621
+
1622
+ func (i Issue346Array ) Len () int {
1623
+ return len (i )
1624
+ }
1625
+
1626
+ func TestIssue346 (t * testing.T ) {
1627
+ code := `Foo[0].Bar`
1628
+
1629
+ env := map [string ]interface {}{
1630
+ "Foo" : Issue346Array {
1631
+ {Bar : "bar" },
1632
+ },
1633
+ }
1634
+ program , err := expr .Compile (code , expr .Env (env ))
1635
+ require .NoError (t , err )
1636
+
1637
+ output , err := expr .Run (program , env )
1638
+ require .NoError (t , err )
1639
+ require .Equal (t , "bar" , output )
1640
+ }
1641
+
1616
1642
func TestCompile_allow_to_use_interface_to_get_an_element_from_map (t * testing.T ) {
1617
1643
code := `{"value": "ok"}[vars.key]`
1618
1644
env := map [string ]interface {}{
Original file line number Diff line number Diff line change @@ -18,9 +18,11 @@ func Fetch(from, i interface{}) interface{} {
18
18
19
19
// Methods can be defined on any type.
20
20
if v .NumMethod () > 0 {
21
- method := v .MethodByName (i .(string ))
22
- if method .IsValid () {
23
- return method .Interface ()
21
+ if methodName , ok := i .(string ); ok {
22
+ method := v .MethodByName (methodName )
23
+ if method .IsValid () {
24
+ return method .Interface ()
25
+ }
24
26
}
25
27
}
26
28
You can’t perform that action at this time.
0 commit comments