Skip to content

Commit

Permalink
Reflect method in Type's pointer first.
Browse files Browse the repository at this point in the history
Create copy only if method exists.
  • Loading branch information
ipsusila committed Jun 5, 2023
1 parent 2182b21 commit e31385f
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions vm/vmExpr.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,14 +266,14 @@ func (runInfo *runInfoStruct) invokeExpr() {
return
}
} else {
// Create pointer value to given struct type which were passed by value
// Check wether method with pointer receiver is defined,
// if yes, invoke it in the copied instance
cv := reflect.New(runInfo.rv.Type())
method := cv.MethodByName(expr.Name)
if method.IsValid() {
method, found := reflect.PointerTo(runInfo.rv.Type()).MethodByName(expr.Name)
if found {
// Create pointer value to given struct type which were passed by value
cv := reflect.New(runInfo.rv.Type())
cv.Elem().Set(runInfo.rv)
runInfo.rv = method
runInfo.rv = cv.Method(method.Index)
return
}
}
Expand Down

0 comments on commit e31385f

Please sign in to comment.