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=-2.9 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FORGED_GMAIL_RCVD,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=no 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 072CA1F462 for ; Mon, 27 May 2019 21:01:09 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 4A8B41209A5; Tue, 28 May 2019 06:01:03 +0900 (JST) Received: from o1678916x28.outbound-mail.sendgrid.net (o1678916x28.outbound-mail.sendgrid.net [167.89.16.28]) by neon.ruby-lang.org (Postfix) with ESMTPS id E86AD12093B for ; Tue, 28 May 2019 06:01:00 +0900 (JST) Received: by filter0097p3iad2.sendgrid.net with SMTP id filter0097p3iad2-6355-5CEC500D-39 2019-05-27 21:01:01.625942921 +0000 UTC m=+357608.243253720 Received: from herokuapp.com (unknown [35.175.137.50]) by ismtpd0024p1mdw1.sendgrid.net (SG) with ESMTP id qtxfcQo1RnmmGH8hR1IxUA for ; Mon, 27 May 2019 21:01:01.455 +0000 (UTC) Date: Mon, 27 May 2019 21:01:01 +0000 (UTC) From: stephen.gregory@gmail.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 68350 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 15877 X-Redmine-Issue-Author: danielwaterworth X-Redmine-Sender: sag 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?E339NU6+=2F5llLo7XwP0p5xrMrSa7QzqkqGg8WqJPMkj7ynNEouYyVJ2gFqrYRS?= =?us-ascii?Q?lyezjIINzfkZ2KVf5ncEAq4XKu19=2FPkZUKmSXpC?= =?us-ascii?Q?xVxB47vf1uexUyRHdHwt1Sv8bOPHp2jv3L6ItFZ?= =?us-ascii?Q?RVh=2FGsr2tHbToG0=2Fqj7fc=2FKX3XOX48ddEoEasFw?= =?us-ascii?Q?qTY5PgjYhELbPJNKfTRlDFPr+1MgyIR=2FbAw=3D=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 92867 Subject: [ruby-core:92867] [Ruby trunk Bug#15877] Incorrect constant lookup result in method on cloned class 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 #15877 has been updated by sag (Stephen Gregory). I tested this on 2.5, 2.4 and the behavior is the same there. Also this applies to subclasses as well. The first class READ determines the values for all of them. ``` ruby class Unrelated TEST='UNRELATED' def test TEST end end class Foo def test TEST end end Bar2 = Foo.clone Bar1 = Foo.clone class Bar1 TEST = 'bar-1' end class Bar2 TEST = 'bar-2' end class Bar3 < Foo TEST = 'bar-3' end puts "Bar2 #{Bar2.new.test}" # Bar2 bar-2 puts "Bar1 #{Bar1.new.test}" # Bar1 bar-2 puts "Bar3 #{Bar3.new.test}" # Bar3 bar-2 puts "Foo #{Foo.new.test}" # Foo bar-2 puts "Unrelated #{Unrelated.new.test}" #Unrelated UNRELATED ``` Interestingly if Bar3 is read first then you get: ``` sample/array_second.rb:12:in `test': uninitialized constant Foo::TEST (NameError) from sample/array_second.rb:30:in `
' ``` ---------------------------------------- Bug #15877: Incorrect constant lookup result in method on cloned class https://bugs.ruby-lang.org/issues/15877#change-78245 * Author: danielwaterworth (Daniel Waterworth) * Status: Open * Priority: Normal * Assignee: * Target version: * ruby -v: 2.6.3 * Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN ---------------------------------------- This behavior seems wrong to me: ``` ruby class Foo def test TEST end end Bar1 = Foo.clone Bar2 = Foo.clone class Bar1 TEST = 'bar-1' end class Bar2 TEST = 'bar-2' end # If these two lines are reordered, 'bar-2' is produced each time p [:bar1_method, Bar1.new.test] # outputs 'bar-1' (correct) p [:bar2_method, Bar2.new.test] # outputs 'bar-1' (incorrect) p [:bar1_const, Bar1::TEST] # outputs 'bar-1' (correct) p [:bar2_const, Bar2::TEST] # outputs 'bar-2' (correct) ``` Possibly related to #9603, #7107 -- https://bugs.ruby-lang.org/