From: "Dan0042 (Daniel DeLorme)" <noreply@...>
Date: 2022-04-19T01:19:41+00:00
Subject: [ruby-core:108284] [Ruby master Feature#18742] Introduce a way to tell if a method invokes the `super` keryword

Issue #18742 has been reported by Dan0042 (Daniel DeLorme).

----------------------------------------
Feature #18742: Introduce a way to tell if a method invokes the `super` keryword
https://bugs.ruby-lang.org/issues/18742

* Author: Dan0042 (Daniel DeLorme)
* Status: Open
* Priority: Normal
----------------------------------------
In order to implement a "no clobber" checker as in #18618, I would like to have a way to check if a method calls `super` or not.

So I'm thinking that something along the line of `Method#calls_super?` could return true/false if the method simply contains the `super` keyword. I'm not really interested in handling weird/artificial edge cases with eval and binding and whatnot.

```ruby
class X
  def a
  end; p instance_method(:a).calls_super? #=> false

  def b
    super
  end; p instance_method(:b).calls_super? #=> true

  def c
    super if false
  end; p instance_method(:c).calls_super? #=> true

  def d
    eval 'super'
  end; p instance_method(:d).calls_super? #=> false (I doubt there's a reasonable way for this to return true)
end
```

With the above it would be possible to warn against a method that has a `super_method` but doesn't use the `super` keyword.



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>