File tree Expand file tree Collapse file tree 2 files changed +31
-3
lines changed Expand file tree Collapse file tree 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) {
16131613 require .Equal (t , 1.0 , output )
16141614}
16151615
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+
16161642func TestCompile_allow_to_use_interface_to_get_an_element_from_map (t * testing.T ) {
16171643 code := `{"value": "ok"}[vars.key]`
16181644 env := map [string ]interface {}{
Original file line number Diff line number Diff line change @@ -18,9 +18,11 @@ func Fetch(from, i interface{}) interface{} {
1818
1919 // Methods can be defined on any type.
2020 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+ }
2426 }
2527 }
2628
You can’t perform that action at this time.
0 commit comments