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-ASN: AS4713 221.184.0.0/13 X-Spam-Status: No, score=-3.9 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS 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 547A91F461 for ; Sun, 25 Aug 2019 00:23:27 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 7E2C3120A9A; Sun, 25 Aug 2019 09:23:18 +0900 (JST) Received: from o1678948x4.outbound-mail.sendgrid.net (o1678948x4.outbound-mail.sendgrid.net [167.89.48.4]) by neon.ruby-lang.org (Postfix) with ESMTPS id 7FE4F120A76 for ; Sun, 25 Aug 2019 09:23:16 +0900 (JST) Received: by filter0037p3iad2.sendgrid.net with SMTP id filter0037p3iad2-32646-5D61D4F7-1D 2019-08-25 00:23:19.431246813 +0000 UTC m=+776411.759884568 Received: from herokuapp.com (unknown [18.234.84.8]) by ismtpd0003p1iad2.sendgrid.net (SG) with ESMTP id INg_5HUVShW2p6tgveYZnw for ; Sun, 25 Aug 2019 00:23:19.376 +0000 (UTC) Date: Sun, 25 Aug 2019 00:23:19 +0000 (UTC) From: merch-redmine@jeremyevans.net Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 70088 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 13249 X-Redmine-Issue-Author: abotalov X-Redmine-Issue-Assignee: ko1 X-Redmine-Sender: jeremyevans0 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?RVE3t853K5scBhbmJHUzZTFFeVC=2FZSUmHZ0Dc+26wcEi2CTgsF1oz0wTSSxGGN?= =?us-ascii?Q?BI86QZ3iKCQ00kQvMcvQHEg0nsBkROfboH38YfX?= =?us-ascii?Q?mElSutxpE3rsnyzV9ub6uHfhVg7HDrmEJJ0AQ84?= =?us-ascii?Q?5kS9jjJg+Ao5SNwK=2FUgESpJY1bWzlTTae9tuqbH?= =?us-ascii?Q?w5x6eVhzoyvEV=2FVnmqyEpClNq0rD3beFKbA=3D=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 94539 Subject: [ruby-core:94539] [Ruby master Bug#13249] Access modifiers don't have an effect inside class methods in Ruby >= 2.3 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="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #13249 has been updated by jeremyevans0 (Jeremy Evans). File warn-scope-visibility-in-method-13249.patch added The warning discussed has not been added yet. Attached is a patch that implements it. While it passes `make check`, there may be corner cases it doesn't handle. I would appreciate review of the changes to `vm_cref_set_visibility`. By adding this warning, I found a related issue in irb, which I submitted a pull request for: https://github.com/ruby/irb/pull/23 ---------------------------------------- Bug #13249: Access modifiers don't have an effect inside class methods in Ruby >= 2.3 https://bugs.ruby-lang.org/issues/13249#change-80980 * Author: abotalov (Andrei Botalov) * Status: Assigned * Priority: Normal * Assignee: ko1 (Koichi Sasada) * Target version: * ruby -v: 2.3.0, 2.4.0 * Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN ---------------------------------------- Simple example: ~~~ ruby class C def self.foo private def bar end end end C.foo C.new.bar ~~~ This code runs fine on Ruby 2.3 and Ruby 2.4. It raises NoMethodError on Ruby 2.2 and prior versions. I would expect an error to be raised. Here is some code that actually uses private access modifier inside a class method - https://github.com/evolve75/RubyTree/blob/db48c35b0a3b96e4da473b095cc00e454d8a9996/lib/tree/utils/camel_case_method_handler.rb#L60 By the way, this code raises an error as expected on Ruby 2.3 and Ruby 2.4: ~~~ ruby class C def self.foo private def bar end end end C.foo C.new.bar # NoMethodError: private method `bar' called ~~~ ---Files-------------------------------- warn-scope-visibility-in-method-13249.patch (4.18 KB) -- https://bugs.ruby-lang.org/