From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-3.9 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id 2DF781F4B4 for ; Mon, 4 Jan 2021 14:48:33 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id F1CA7120C06; Mon, 4 Jan 2021 23:47:36 +0900 (JST) Received: from xtrwkhkc.outbound-mail.sendgrid.net (xtrwkhkc.outbound-mail.sendgrid.net [167.89.16.28]) by neon.ruby-lang.org (Postfix) with ESMTPS id A751A120B27 for ; Mon, 4 Jan 2021 23:47:34 +0900 (JST) Received: by filterdrecv-p3las1-685fdc5bbc-ph5zt with SMTP id filterdrecv-p3las1-685fdc5bbc-ph5zt-20-5FF32AAF-43 2021-01-04 14:48:15.638541093 +0000 UTC m=+2130363.412509659 Received: from herokuapp.com (unknown) by geopod-ismtpd-4-2 (SG) with ESMTP id 7O1H9clPTtC1-gZFF82_tw for ; Mon, 04 Jan 2021 14:48:15.426 +0000 (UTC) Date: Mon, 04 Jan 2021 14:48:15 +0000 (UTC) From: benedikt@benediktdeicke.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 77819 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Bug X-Redmine-Issue-Id: 17509 X-Redmine-Issue-Author: benediktdeicke X-Redmine-Sender: benediktdeicke X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: =?us-ascii?Q?emrvvLqKqxvLMUtg8LtsURey19bRfaeUa2oEtPIJRykD5+zHP4Lo7ePPBAvEfr?= =?us-ascii?Q?e16xrS1SDW4o1KDSI=2F17yuQwN922ZI7PRbmbyzc?= =?us-ascii?Q?UBYSCPvUay6fILWL6+HhsYbMEtE2UaJqj7Qm+w4?= =?us-ascii?Q?zVXs2ojpro6zJpI7SWJJomlGR07Q1UH8H3lf0SW?= =?us-ascii?Q?7KcR=2FoHFYY=2F3Nh7ZAliF2ooljuyeb4mAgx0Rzpf?= =?us-ascii?Q?xyCm8A4tfC3CMvEDU=3D?= To: ruby-core@ruby-lang.org X-Entity-ID: b/2+PoftWZ6GuOu3b0IycA== X-ML-Name: ruby-core X-Mail-Count: 101912 Subject: [ruby-core:101912] [Ruby master Bug#17509] Custom respond_to? methods in modules break defined?(super) X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #17509 has been reported by benediktdeicke (Benedikt Deicke). ---------------------------------------- Bug #17509: Custom respond_to? methods in modules break defined?(super) https://bugs.ruby-lang.org/issues/17509 * Author: benediktdeicke (Benedikt Deicke) * Status: Open * Priority: Normal * ruby -v: ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-darwin19] * Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN ---------------------------------------- When using `defined?(super)` to check that a superclass method exists befor= e calling `super`, including modules with a custom `respond_to?` method see= ms to break the check so it wrongfully returns a truthy value, even though = the superclass method doesn't exist. This only happens on Ruby 3.0.0 and works fine on previous Ruby versions. T= his is possibly related to this change: https://github.com/ruby/ruby/pull/3= 777 ### Example = ``` module SomeModule def a_method defined?(super) ? super : :no_super_method end end module RespondModule def respond_to?(*) super end end class PlainClass include SomeModule end class ModuleClass include RespondModule include SomeModule end puts "PlainClass: #{PlainClass.new.a_method}" puts "ModuleClass: #{ModuleClass.new.a_method}" ``` ### Actual Result on Ruby 3.0.0p0 ``` PlainClass: no_super_method test.rb:3:in `a_method': super: no superclass method `a_method' for # (NoMethodError) Did you mean? method from test.rb:24:in `
' ``` ### Expected Result (like on older versions) ``` PlainClass: no_super_method ModuleClass: no_super_method ``` Thanks to Rafael Fran=E7a for helping me unravel this. = ---Files-------------------------------- test.rb (359 Bytes) -- = https://bugs.ruby-lang.org/ Unsubscribe: