-
Notifications
You must be signed in to change notification settings - Fork 553
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
Method resolution still searches inside bareword handles despite no feature "bareword_filehandles"
#19426
Comments
|
Equally, even |
|
What should: do here? The The "magical" conversion from a string to an IO object is done in opmethod_stash(), which doesn't distinguish between literals or variables here. I have a simple patch that doesn't allow the conversion from string to IO under no bareword handles, but it's also going to exclude the |
|
I spent some time on this trying to make it so The below was done with a patch that prevents IO lookup when the class is specified as a bareword: Note the difference in behaviour for the non-bareword calls, this happens since after the bareword call skips the IO lookup, it looks up the name as a stash, which caches the stash lookup, so further calls are found in the cache (near the Also, since the cache isn't copied into a thread (the entries in the stash cache are IVs representing HV pointers) a new thread treats the non-constant stash lookups as IO lookups again: So at this point such a fix seems worse than the problem it's trying to fix. |
This prevents SomeBareword from being looked up as a filehandle: no feature "bareword_filehandles"; SomeBareword->method(); Since "bareword_filehandles" is explicitly about bareword handles, it does not prevent other string to object/class look ups from resolving the class as a filehandle, eg for the following: "SomeLiteral"->method(); my $x = "SomeVariable"; $x->method(); both are looked up as file handles per normal. Note that in any of these cases, with or without the bareword_filehandles feature, if the name is a bareword that has been resolved as a class name since the last time the stash cache was cleared, it will be resolved as a class name, not a filehandle. Fixes Perl#19426
|
After some thought, I realized that the name doesn't need to be used as a class in the current scope to populate the stash cache, it may have been used in another scope, which will change the behaviour of So for robustness, if you're using bareword handles, use upper-case names to keep them distinct from the typical camel-case class names. Since it may not show in email, I'll mention I've also added a PR fixing this issue for barewords. |
This prevents SomeBareword from being looked up as a filehandle: no feature "bareword_filehandles"; SomeBareword->method(); Since "bareword_filehandles" is explicitly about bareword handles, it does not prevent other string to object/class look ups from resolving the class as a filehandle, eg for the following: "SomeLiteral"->method(); my $x = "SomeVariable"; $x->method(); both are looked up as file handles per normal. Note that in any of these cases, with or without the bareword_filehandles feature, if the name is a bareword that has been resolved as a class name since the last time the stash cache was cleared, it will be resolved as a class name, not a filehandle. Fixes Perl#19426 # Conflicts: # opcode.h
This prevents SomeBareword from being looked up as a filehandle: no feature "bareword_filehandles"; SomeBareword->method(); Since "bareword_filehandles" is explicitly about bareword handles, it does not prevent other string to object/class look ups from resolving the class as a filehandle, eg for the following: "SomeLiteral"->method(); my $x = "SomeVariable"; $x->method(); both are looked up as file handles per normal. Note that in any of these cases, with or without the bareword_filehandles feature, if the name is a bareword that has been resolved as a class name since the last time the stash cache was cleared, it will be resolved as a class name, not a filehandle. Fixes Perl#19426 # Conflicts: # opcode.h
This prevents SomeBareword from being looked up as a filehandle: no feature "bareword_filehandles"; SomeBareword->method(); Since "bareword_filehandles" is explicitly about bareword handles, it does not prevent other string to object/class look ups from resolving the class as a filehandle, eg for the following: "SomeLiteral"->method(); my $x = "SomeVariable"; $x->method(); both are looked up as file handles per normal. Note that in any of these cases, with or without the bareword_filehandles feature, if the name is a bareword that has been resolved as a class name since the last time the stash cache was cleared, it will be resolved as a class name, not a filehandle. Fixes Perl#19426 # Conflicts: # opcode.h # Conflicts: # opcode.h
This prevents SomeBareword from being looked up as a filehandle: no feature "bareword_filehandles"; SomeBareword->method(); Since "bareword_filehandles" is explicitly about bareword handles, it does not prevent other string to object/class look ups from resolving the class as a filehandle, eg for the following: "SomeLiteral"->method(); my $x = "SomeVariable"; $x->method(); both are looked up as file handles per normal. Note that in any of these cases, with or without the bareword_filehandles feature, if the name is a bareword that has been resolved as a class name since the last time the stash cache was cleared, it will be resolved as a class name, not a filehandle. Fixes Perl#19426 # Conflicts: # opcode.h # Conflicts: # opcode.h
This prevents SomeBareword from being looked up as a filehandle: no feature "bareword_filehandles"; SomeBareword->method(); Since "bareword_filehandles" is explicitly about bareword handles, it does not prevent other string to object/class look ups from resolving the class as a filehandle, eg for the following: "SomeLiteral"->method(); my $x = "SomeVariable"; $x->method(); both are looked up as file handles per normal. Note that in any of these cases, with or without the bareword_filehandles feature, if the name is a bareword that has been resolved as a class name since the last time the stash cache was cleared, it will be resolved as a class name, not a filehandle. Fixes #19426 # Conflicts: # opcode.h # Conflicts: # opcode.h
Fails with:
This indicated that, despite the
no feature "bareword::filehandles"that was in scope at toplevel, it nonetheless tried to resolve the->donemethod call via that bareword handle that was previously opened earlier, taking precedence over the otherwise-expected resolve via named package.The text was updated successfully, but these errors were encountered: