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

Mark frame-aware method names with bang suffix for ostruct #8206

Merged
merged 2 commits into from Apr 23, 2024

Conversation

headius
Copy link
Member

@headius headius commented Apr 22, 2024

Also flag frame names with "!" for ostruct

The ostruct library aliases all methods from Object/Kernel with a bang suffix ("!") to allow them to be callable even though the OpenStruct should support them as field names. Because we use record these names in a table of known frame-aware methods, we have typically warned when aliasing them. This rarely comes up, since aliasing usually is accompanied by wrapping, which breaks their behavior on all implementations, but this aliasing in ostruct is unusual and pervasive, leading to issues like #8200.

This patch assumes we're going to have issues with ostruct forever and eagerly adds the "!" names alongside the regular names for all method names that match /[a-z_]/, so taht existing methods and future methods will behavior properly and not warn when aliased.

It adds a small amount to startup, since these method names must be added twice, but there are not many such names in the system.

Fixes #8200

Replaces #7524

The ostruct library aliases all methods from Object/Kernel with
a bang suffix ("!") to allow them to be callable even though the
OpenStruct should support them as field names. Because we use
record these names in a table of known frame-aware methods, we
have typically warned when aliasing them. This rarely comes up,
since aliasing usually is accompanied by wrapping, which breaks
their behavior on all implementations, but this aliasing in
ostruct is unusual and pervasive, leading to issues like jruby#8200.

This patch assumes we're going to have issues with ostruct forever
and eagerly adds the "!" names alongside the regular names for all
method names that match /[a-z_]/, so taht existing methods and
future methods will behavior properly and not warn when aliased.

It adds a small amount to startup, since these method names must
be added twice, but there are not many such names in the system.

Fixes jruby#8200

Replaces jruby#7524
@headius headius added this to the JRuby 9.4.7.0 milestone Apr 22, 2024
@headius headius merged commit 9af3b8f into jruby:master Apr 23, 2024
74 checks passed
@headius headius deleted the flag_banged_frame_methods branch April 23, 2024 20:16
@headius
Copy link
Member Author

headius commented Apr 23, 2024

A total of 47 additional names are added to the list of frame-aware methods:

__callee__!
__dir__!
__method__!
attr!
attr_accessor!
attr_reader!
attr_writer!
autoload!
binding!
chomp!
chop!
class_eval!
class_exec!
define_method!
eval!
extend_proxy!
foreach!
gets!
gsub!
index!
instance_eval!
instance_exec!
instance_method!
last_match!
local_variables!
match!
method!
module_eval!
module_exec!
module_function!
nesting!
partition!
print!
private!
protected!
public!
public_send!
readline!
refine!
require_relative!
rindex!
rpartition!
scan!
slice!
sub!
used_modules!
using!

This translates to 69 additional adds during -e 1 startup due to some methods being defined in multiple classes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Warnings emitted by requiring 'ostruct'
1 participant