-
Notifications
You must be signed in to change notification settings - Fork 364
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
flag.Parse() causes panic when printing help #1276
Comments
mvertes
added a commit
that referenced
this issue
Oct 7, 2021
When an interpreter type implementing an interface is used by the runtime, the runtime can extract its type and create new values using reflect, and call methods on it. The problem is that there will be no interpreted method counterpart in this case, which make wrapper panic. Allow the String() method wrapper to always succeed and return an empty string if no interpreted method is present. This allow scripts to define custom flag.Value types on which the runtime internally instantiates values using reflect (see isZeroValue in Go src/flag/flag.go). This workaround could be generalized to all wrappers if necessary. At this moment, it is convenient to keep the default behavior of expececting instantiated interpreter methods, in order to catch interpreter bugs related to interfaces. Fixes #1276.
@Bai-Yingjie Thanks, and congrats, your analysis is correct, but as wrappers are generated by extract using templates, I prefer to provide the fix myself in #1281. I fixed also another related problem due to unused arguments in wrapped methods, seen here in Thanks |
traefiker
pushed a commit
that referenced
this issue
Oct 8, 2021
When an interpreter type implementing an interface is used by the runtime, the runtime can extract its type and create new values using reflect, and call methods on it. The problem is that there will be no interpreted method counterpart in this case, which make wrapper panic. Allow the String() method wrapper to always succeed and return an empty string if no interpreted method is present. This allow scripts to define custom flag.Value types on which the runtime internally instantiates values using reflect (see isZeroValue in Go src/flag/flag.go). This workaround could be generalized to all wrappers if necessary. At this moment, it is convenient to keep the default behavior of expececting instantiated interpreter methods, in order to catch interpreter bugs related to interfaces. Fixes #1276.
traefiker
pushed a commit
that referenced
this issue
Oct 8, 2021
When an interpreter type implementing an interface is used by the runtime, the runtime can extract its type and create new values using reflect, and call methods on it. The problem is that there will be no interpreted method counterpart in this case, which makes wrapper panic. Allow the String() method wrapper to always succeed and return an empty string if no interpreted method is present. This allows scripts to define custom flag.Value types on which the runtime internally instantiates values using reflect (see isZeroValue in Go src/flag/flag.go). This workaround could be generalized to all wrappers if necessary. At this moment, it is convenient to keep the default behavior of expecting instantiated interpreter methods, in order to catch interpreter bugs related to interfaces. Fixes #1276.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The following program
sample.go
triggers an unexpected resultExpected result
Got
Yaegi Version
286d6c6
Additional Notes
When user inputs
-h
,flag.Parse()
will callPrintDefaults()
, this is where the panic triggered.By studying package flag code,
PrintDefaults()
callsisZeroValue()
:which calls the interface wrapper
stdlib._flag_Value.String
but with zero value receiver, which ends up with nil func call toW.WString
A possible fix would be adding a nil checker in the template to generate code like this:
I am new to yaegi and will be very happy to deliver this fix if it is acceptable.
The text was updated successfully, but these errors were encountered: