Skip to content

OpenStruct aliases critical builtin methods to "!" versions #30

@headius

Description

@headius

JRuby warns whenever a core method that accesses the caller's frame gets aliased, since we use the name of the method to detect that a frame should be pushed.

However current OpenStruct versions are aliasing several critical builtin methods that it should not, resulting in warnings on JRuby:

$ jruby -we 'require "ostruct"'
/Users/headius/projects/jruby/lib/ruby/stdlib/ostruct.rb:446: warning: OpenStruct#define_singleton_method accesses caller method's state and should not be aliased
/Users/headius/projects/jruby/lib/ruby/stdlib/ostruct.rb:446: warning: OpenStruct#!~ accesses caller method's state and should not be aliased
/Users/headius/projects/jruby/lib/ruby/stdlib/ostruct.rb:446: warning: OpenStruct#=~ accesses caller method's state and should not be aliased
/Users/headius/projects/jruby/lib/ruby/stdlib/ostruct.rb:446: warning: OpenStruct#instance_exec accesses caller method's state and should not be aliased
/Users/headius/projects/jruby/lib/ruby/stdlib/ostruct.rb:446: warning: OpenStruct#instance_eval accesses caller method's state and should not be aliased

We warn because aliasing very frequently involves wrapping the original method with a new pure-Ruby method, breaking the framing requirements of the aliased original.

  • define_singleton_method accesses the caller frame for visibility.
  • !~ and =~ access the caller frame for the backref frame-local $~.
  • instance_exec and instance_eval capture the caller frame for use as a parent frame for the eval.

I believe OpenStruct should not be aliasing these methods.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions