Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

interp: improve handling of methods defined on interfaces #1516

Merged
merged 12 commits into from
Mar 6, 2023

Conversation

mvertes
Copy link
Member

@mvertes mvertes commented Feb 23, 2023

For methods defined on interfaces (vs concrete methods), the resolution of the method is necessarily delayed at the run time and can not be completed at compile time.

The selectorExpr processing has been changed to correctly identify calls on interface methods which were confused as fields rather than methods (due to the fact that in a interface definition, methods are fields of the interface).

Then at runtime, method lookup has been fixed to correctly recurse in nested valueInterface wrappers and to find embedded interface fields in case of struct or pointer to struct.

Finally, remove receiver processing in call().The receiver is already processed at method resolution and in genFunctionWrapper. Removing redundant processing in call fixes handling of variadic method, simplifies the code and makes it faster.

With those fixes, it is now possible to load and run go.uber.org/zap in yaegi. In turn, it makes possible for yaegi to run plugins dependent on zap, such as coraza-waf.

Fixes #1515,
Fixes #1172,
Fixes #1275,
Fixes #1485.

For methods defined on interfaces (vs concrete methods), the resolution
of the method is necessarily delayed at the run time and can not be
completed at compile time.

The selectorExpr processing has been changed to correctly identify
calls on interface methods which were confused as fields rather
than methods (due to the fact that in a interface definition, methods
are fields of the interface).

Then at runtime, method lookup has been fixed to correctly recurse in
nested valueInterface wrappers and to find embedded interface fields
in case of struct or pointer to structs.

Fixes traefik#1515.
@mvertes mvertes added this to the v0.15.x milestone Feb 23, 2023
@mvertes mvertes marked this pull request as draft February 23, 2023 14:18
@mvertes mvertes marked this pull request as ready for review February 24, 2023 09:12
The receiver is already processed at method resolution and in
genFunctionWrapper. Removing redundant processing in call
fixes handling of variadic method, simplifies the code and
makes it faster.

With this commit, it is now possible to run coraza-waf plugin
in traefik.
interp/cfg.go Outdated Show resolved Hide resolved
interp/cfg.go Outdated Show resolved Hide resolved
interp/run.go Show resolved Hide resolved
interp/run.go Show resolved Hide resolved
mvertes and others added 4 commits March 6, 2023 12:10
Co-authored-by: mpl <mathieu.lonjaret@gmail.com>
Co-authored-by: mpl <mathieu.lonjaret@gmail.com>
Co-authored-by: mpl <mathieu.lonjaret@gmail.com>
interp/cfg.go Outdated Show resolved Hide resolved
interp/cfg.go Outdated Show resolved Hide resolved
mvertes and others added 2 commits March 6, 2023 16:37
Co-authored-by: mpl <mathieu.lonjaret@gmail.com>
Co-authored-by: mpl <mathieu.lonjaret@gmail.com>
@mvertes mvertes deleted the fix-1515 branch March 6, 2023 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/core bug Something isn't working
Projects
None yet
3 participants