Skip to content

Add method! and public_send! for OpenStruct warnings#7524

Draft
headius wants to merge 1 commit intojruby:masterfrom
headius:suppress_ostruct_warnings
Draft

Add method! and public_send! for OpenStruct warnings#7524
headius wants to merge 1 commit intojruby:masterfrom
headius:suppress_ostruct_warnings

Conversation

@headius
Copy link
Member

@headius headius commented Dec 14, 2022

Due to these methods now accessing the caller's scope (for refinements) they now warn when being aliased to another name. We suppress the warning when the target name has a superset of client frame reads, so this patch adds method! and public_send! with SCOPE read.

This is not ideal, since any future method gaining frame fields will need to have the same treatment, and other similar methods are being skipped by OpenStruct (by our request). However this suppresses the warning for now and we can work on a long-term option.

Due to these methods now accessing the caller's scope (for
refinements) they now warn when being aliased to another name.
We suppress the warning when the target name has a superset of
client frame reads, so this patch adds `method!` and
`public_send!` with SCOPE read.

This is not ideal, since any future method gaining frame fields
will need to have the same treatment, and other similar methods
are being skipped by OpenStruct (by our request). However this
suppresses the warning for now and we can work on a long-term
option.
@headius headius added this to the JRuby 9.4.1.0 milestone Dec 14, 2022
@headius headius modified the milestones: JRuby 9.4.1.0, JRuby 9.4.2.0 Feb 6, 2023
@headius headius modified the milestones: JRuby 9.4.2.0, JRuby 9.4.3.0 Feb 28, 2023
@headius headius modified the milestones: JRuby 9.4.3.0, JRuby 9.4.4.0 Jun 6, 2023
@headius headius modified the milestones: JRuby 9.4.4.0, JRuby 9.4.5.0 Oct 11, 2023
@headius
Copy link
Member Author

headius commented Oct 11, 2023

Still not sure I like this solution, so bumping.

@enebo enebo modified the milestones: JRuby 9.4.5.0, JRuby 9.4.6.0 Oct 31, 2023
@headius
Copy link
Member Author

headius commented Feb 13, 2024

These warnings are now only displayed in verbose mode, so we can reevaluate whether this is still necessary in 9.5.

@headius headius modified the milestones: JRuby 9.4.6.0, JRuby 9.5.0.0 Feb 13, 2024
headius added a commit to headius/jruby that referenced this pull request Apr 22, 2024
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 added a commit to headius/jruby that referenced this pull request Apr 22, 2024
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
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.

2 participants