From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: poffice@blade.nagaokaut.ac.jp Delivered-To: poffice@blade.nagaokaut.ac.jp Received: from kankan.nagaokaut.ac.jp (kankan.nagaokaut.ac.jp [133.44.2.24]) by blade.nagaokaut.ac.jp (Postfix) with ESMTP id 2694119C003E for ; Sat, 7 Nov 2015 12:30:25 +0900 (JST) Received: from voscc.nagaokaut.ac.jp (voscc.nagaokaut.ac.jp [133.44.1.100]) by kankan.nagaokaut.ac.jp (Postfix) with ESMTP id 6D507B5D886 for ; Sat, 7 Nov 2015 12:59:35 +0900 (JST) Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by voscc.nagaokaut.ac.jp (Postfix) with ESMTP id 86D7318CC7B8 for ; Sat, 7 Nov 2015 12:59:35 +0900 (JST) Received: from [221.186.184.76] (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 9BF35120487; Sat, 7 Nov 2015 12:59:32 +0900 (JST) X-Original-To: ruby-core@ruby-lang.org Delivered-To: ruby-core@ruby-lang.org Received: from o2.heroku.sendgrid.net (o2.heroku.sendgrid.net [67.228.50.55]) by neon.ruby-lang.org (Postfix) with ESMTPS id 4A1A312044E for ; Sat, 7 Nov 2015 12:59:28 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sendgrid.me; h=from:to:references:subject:mime-version:content-type:content-transfer-encoding:list-id; s=smtpapi; bh=rF23MrWVO8LbfsNQjd009qj+TIg=; b=grdj8da/O1cK06fNQ2 i6dhe1aSrN5CKTOvbn9XUcWp4Gt5/8o4yagmGGN1rMqNqkhSWduKNUx+VsWH3ZE+ iTP30CbnmYTq4f1RZtmLRCK/dhwAWrWVFEsKLT+IEjSOCis17EJMpTSvV+lWkvI6 eqZMl0E4AC2mKIjfor0Asio+I= Received: by filter-424.sjc1.sendgrid.net with SMTP id filter-424.4741.563D771C15 2015-11-07 03:59:24.719148033 +0000 UTC Received: from herokuapp.com (ec2-174-129-101-222.compute-1.amazonaws.com [174.129.101.222]) by ismtpd0002p1iad1.sendgrid.net (SG) with ESMTP id _IlDNiiET7enPk1Vph3WyQ Sat, 07 Nov 2015 03:59:24.702 +0000 (UTC) Date: Sat, 07 Nov 2015 03:59:24 +0000 From: mike@oobak.org To: ruby-core@ruby-lang.org Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Redmine-MailingListIntegration-Message-Ids: 46017 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 11659 X-Redmine-Issue-Author: mwpastore X-Redmine-Sender: mwpastore 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: ync6xU2WACa70kv/Ymy4QrNMhiuLXJG8OTL2vJD1yS7UtNWVFDWhxCkt61BlAeQBEIPDJNwFPmJatY JWjeypSmMo05Qe95S4lcsdUMXyxD2CbGQ8L/3BYe3tpjondSPT2Drc3BnMNmFWtknosp4VRRC6Sn/1 LMBYU9EPXL6ar40= X-ML-Name: ruby-core X-Mail-Count: 71376 Subject: [ruby-core:71376] [Ruby trunk - Bug #11659] Strange behavior setting previously-undefined local variables with a statement modifier 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: , Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #11659 has been updated by Mike Pastore. That's not a typo. :-) I wanted to intentionally compare and contrast between a scenario where the same variable was being checked and set (#2) and a scenario where two different variables are in play (#4). I understand about the parser now, and in fact found another question/answer on SO that explains it in a similar manner. So it's not a bug, per se. It is kind of a Ruby "WTF", though, and in this humble Rubyist's opinion violates POLA pretty badly. ---------------------------------------- Bug #11659: Strange behavior setting previously-undefined local variables with a statement modifier https://bugs.ruby-lang.org/issues/11659#change-54747 * Author: Mike Pastore * Status: Open * Priority: Normal * Assignee: * ruby -v: ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-linux] * Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN ---------------------------------------- Consider a previously-undefined local variable `var1`: ~~~ irb(main):001:0> if defined?(var1).nil?; var1 = 'default'; end; var1 => "default" ~~~ Consider previously-undefined local variables `var1` and `var2`: ~~~ irb(main):001:0> var2 = 'default' if defined?(var1).nil?; var2 => "default" ~~~ Consider a previously-undefined local variable `var3`: ~~~ irb(main):001:0> var3 = 'default' if true; var3 => "default" ~~~ Consider a previously-undefined local variable `var4`: ~~~ irb(main):001:0> var4 = 'default' if defined?(var4).nil?; var4 => nil ~~~ Oops! Why is `var4` nil? Logically, considering the prior examples, it should be 'default'. Or are we missing something? http://stackoverflow.com/questions/33537059/unless-defined-is-not-working-in-my-code -- https://bugs.ruby-lang.org/