Skip to content

Commit

Permalink
Also flag frame names with "!" for ostruct
Browse files Browse the repository at this point in the history
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
  • Loading branch information
headius committed Apr 22, 2024
1 parent e736637 commit e732f53
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions core/src/main/java/org/jruby/anno/AnnotationHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ public static void populateMethodIndex(Map<Set<FrameField>, List<String>> access
for (String name : names) {
if (uniqueValues.add(name)) {
joiner.add(name);

// in order to support these names aliased with "!" we eagerly add those names as well (jruby/jruby#8200)
if (name.matches("^[a-z_]+$")) {
joiner.add(name + '!');
}
}
}
String namesJoined = joiner.toString();
Expand Down

0 comments on commit e732f53

Please sign in to comment.