Ruby Issue Tracking System: Issueshttps://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112019-06-10T11:15:38ZRuby Issue Tracking System
Redmine Ruby master - Bug #15910 (Rejected): $. doesn't hold the linenumber anymore when reading a CSV-fi...https://redmine.ruby-lang.org/issues/159102019-06-10T11:15:38Zrovf (Ronald Fischer)ynnor@mm.st
<p>Example program:</p>
<pre><code>require 'csv'
IFS=';'
CSV_OPTIONS = { col_sep: IFS, external_encoding: Encoding::ISO_8859_1, internal_encoding: Encoding::UTF_8 }
CSV.new($stdin, CSV_OPTIONS).each do
|row|
puts "::::line #{$.} row=#{row}"
end%
</code></pre>
<p>With this program, I could dump a semicolon-delimited CSV file, with line numbers. Now the line number always displays as 0. Has the implementation of CSV changed?</p>
<p>See also <a href="https://stackoverflow.com/questions/56524941/is-special-variable-gone-from-ruby" class="external">https://stackoverflow.com/questions/56524941/is-special-variable-gone-from-ruby</a></p> Ruby master - Bug #13817 (Closed): test/unit breaks Hashhttps://redmine.ruby-lang.org/issues/138172017-08-15T11:18:39Zrovf (Ronald Fischer)ynnor@mm.st
<p>Consider the following program:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="c1">#!/usr/bin/env ruby</span>
<span class="k">BEGIN</span> <span class="p">{</span><span class="vg">$VERBOSE</span> <span class="o">=</span> <span class="kp">true</span><span class="p">}</span>
<span class="nb">require</span> <span class="s1">'test/unit'</span>
<span class="k">class</span> <span class="nc">Hash</span>
<span class="no">STDERR</span><span class="p">.</span><span class="nf">puts</span> <span class="nb">method_defined?</span><span class="p">(</span><span class="ss">:<<</span><span class="p">)</span>
<span class="k">alias</span> <span class="o"><<</span> <span class="n">merge!</span>
<span class="no">STDERR</span><span class="p">.</span><span class="nf">puts</span> <span class="nb">method_defined?</span><span class="p">(</span><span class="ss">:<<</span><span class="p">)</span>
<span class="k">end</span>
</code></pre>
<p>In older Ruby versions (1.9.3, 2.3.3), the output of this program was:</p>
<pre><code>false
true
</code></pre>
<p>In Ruby 2.4.1, the output is</p>
<pre><code>false
~/work/stash/vp5/src/test/test_xx.rb:6: warning: method redefined; discarding old <<
true
</code></pre>
<p>Please note:</p>
<ol>
<li>The warning occurs, even though <code>method_defined?</code> tells us that no <code><<</code> method is in <code>Hash</code>.</li>
<li>The warning disappears, when we do <strong>not</strong> require test/unit, which suggests that the problem is caused by test/unit</li>
<li>Changing the offending line to <code>alias :<< :merge!</code> does not make any difference</li>
</ol> Ruby master - Feature #13763 (Open): Trigger "unused variable warning" for unused variables in pa...https://redmine.ruby-lang.org/issues/137632017-07-24T12:16:29Zrovf (Ronald Fischer)ynnor@mm.st
<p>Consider the following program nowa.rb:</p>
<pre><code>def foo(a)
end
%w(x).each {|y|}
foo(1)
z=5
</code></pre>
<p>If I syntax-check it with <em>ruby -cw nowa.rb</em> I get the following warning:</p>
<pre><code>nowa.rb:5: warning: assigned but unused variable - z
</code></pre>
<p>Ruby complains about z, but does not complain about a and y, even though these are also variables which receive a value which never is used. I suggest to issue a warning in these cases too.</p>
<p>Tested with: ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-cygwin]</p> Ruby master - Misc #13634 (Open): NilClass is lying about respond_to?(:clone)https://redmine.ruby-lang.org/issues/136342017-06-06T08:12:46Zrovf (Ronald Fischer)ynnor@mm.st
<p>I put this under "Misc", because I'm not sure, whether this is a bug, a feature request, or maybe a deliberate (but for me obscure) decision in language design:</p>
<p>NilClass (and Fixnum) do not support clone. That's fine. However,</p>
<p>nil.respons_to?(:clone) returns true.</p>
<p>This means that we <em>can</em> ask nil to clone itself (we don't get a NoMethod error), it's just trying to do so throws an exception.</p>
<p>I stumbled over this problem when I had an collection of objects of different types, and wanted to apply :clone to some of them. My code went approximately like this:</p>
<p>object = collection[key]<br>
return object.respond_to?(:clone) ? object.clone : object</p>
<p>This doesn't work, if object is nil, true, false, a Symbol or a Fixnum, because all of them claim to respond to :clone.</p>
<p>Of course, there is a trivial workaround (I just have to rescue the exception), but I find this language design not really intuitive. I think there are two possibilites, how this can be made better:</p>
<p>(1) If we decide, that nil is not clonable (because there can be only one nil), then respond_to?(:clone) should IMHO simply be false.</p>
<p>(2) However, there might be even be a reason why :clone should be applicable. Note that the usual semantics of clone is to do a shallow copy (for instance, when we 'clone' a nested array). If we want to have a deep copy, the usual approach is Marshal.load(Marshal.dump(object)). Now the odd thing is that we can not "shallowly copy" nil, i.e. nil.clone is forbidden, but we can do a deep copy, i.e. Marshal.load(Marshal.dump(nil)) works. So, an alternative would be to have nil.clone simply return the identical object.</p>
<p>Both (1) seems to me a sound solution. The solution (2) has the drawback that we can't guarantee anymore that x.clone has a different object id than x, but is probably the behaviour a programmer would intuitively expect.</p> Ruby master - Bug #13612 (Closed): Segmentation Faulthttps://redmine.ruby-lang.org/issues/136122017-05-30T10:33:00Zrovf (Ronald Fischer)ynnor@mm.st
<p>I got a segmentation fault, fllowed by the message "You may have encountered a bug in the Ruby interpreter or extension libraries.". See attachment.</p>
<p>The exception occured in this piece of code:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"> <span class="k">class</span> <span class="nc">EXPERT</span>
<span class="no">FIND_CHAIN_FOR_POS_FILTER_PIPELINE</span> <span class="o">=</span>
<span class="p">[</span>
<span class="ss">:no_filter</span><span class="p">,</span>
<span class="ss">:filter_by_etkz_e</span><span class="p">,</span>
<span class="ss">:filter_chain_in_chain</span><span class="p">,</span>
<span class="p">].</span><span class="nf">each</span>
<span class="k">def</span> <span class="nf">find_chain_for_pos</span><span class="p">(</span><span class="n">sw_lines_for_module</span><span class="p">,</span> <span class="n">wsc_sw_lines</span><span class="p">)</span>
<span class="no">FIND_CHAIN_FOR_POS_FILTER_PIPELINE</span><span class="p">.</span><span class="nf">rewind</span>
<span class="k">begin</span>
<span class="k">while</span> <span class="no">NVP</span><span class="p">.</span><span class="nf">multiple_grpids?</span><span class="p">(</span><span class="n">sw_lines_for_module</span><span class="p">)</span>
<span class="n">filter_method_symb</span> <span class="o">=</span> <span class="no">FIND_CHAIN_FOR_POS_FILTER_PIPELINE</span><span class="p">.</span><span class="nf">next</span> <span class="c1"># <----- This is line 30, where the exception reportedly occured.</span>
<span class="n">sw_lines_for_module</span> <span class="o">=</span> <span class="no">NVP</span><span class="p">.</span><span class="nf">send</span><span class="p">(</span><span class="n">filter_method_symb</span><span class="p">,</span> <span class="n">br</span><span class="p">,</span> <span class="n">sw_lines_for_module</span><span class="p">)</span>
<span class="k">end</span>
<span class="k">rescue</span> <span class="no">StopIteration</span>
<span class="no">LOG</span><span class="p">.</span><span class="nf">trace</span> <span class="s2">"Could not find unique GRPID"</span>
<span class="k">end</span>
<span class="k">end</span>
<span class="k">end</span>
</code></pre>
<p>The segmentation fault occurs only after this method has been executed repeatedly several hundred times.</p> Ruby master - Bug #13214 (Closed): FileUtils::mkdir_p creates additional (unrequested) directory ...https://redmine.ruby-lang.org/issues/132142017-02-14T12:04:39Zrovf (Ronald Fischer)ynnor@mm.st
<p>FileUtils.mkdir(SOMEPATH) on Cygwin will create a directory ./c: in addition to SOMEPATH, if the following two conditions are met:</p>
<p>-SOMEPATH must be specified as absolute path using Windows drive letters and forward slashes as separators (so called "mixed-mode pathes" in Cygwin technologiy; see man cygpath).</p>
<ul>
<li>The parent directory of SOMEPATH does not exist.</li>
</ul>
<p>The enclosed zip file demonstrates the problem. To run it, extract it to some directory, cd to this directory and then source the shell script file by typing</p>
<p>. mkdir_test.shell</p>
<p>This script will create a directory c:/tmp, set up everything so that the error can become evident, and the runs mkdir_test.rb. This in turn creates a directory c:/tmp/foo/bar, and shows (using File.exist?), that in addition a director ./c: has been created. If you study the Ruby code, it will be obvious what's going wrong.</p>
<p>My guess is that at one point, FileUtils::mkdir needs to decide whether the path to be created is relative or absolute, and since c:/ is an absolute path only in the realm of Cygwin, but not in Unix, it creates a local directory ./c:. Note however that it does NOT create a full path ./c:/tmp/foo/bar. The requested directory <em>is</em> created as (in Windows notation) C:\TMP\FOO\BAR, as requested, and from this, I conclude, that mkdir_p is, by and large, Cygwin-aware. The error is not that the requested directory was not created, but that this mkdir_p call has created two directories, not one. Indeed, if I pass the path as</p>
<pre><code>FileUtils.mkdir_p('/cygdrive/c/tmp/foo/bar')
</code></pre>
<p>everything goes fine.</p>
<p>I can reproduce the error using the 64 Bit version of Cygwin. I don't know whether it also occurs in 32 Bit Cygwin.</p> Ruby master - Bug #13008 (Closed): File::basename fails if extension contains a colonhttps://redmine.ruby-lang.org/issues/130082016-12-05T13:41:04Zrovf (Ronald Fischer)ynnor@mm.st
<pre><code> File.basename('a/b/c.d:12')
</code></pre>
<p>returns</p>
<pre><code>c.d
</code></pre>
<p>but should return</p>
<pre><code>c.d:12
</code></pre> Ruby master - Misc #12641 (Third Party's Issue): JSON documentation incompletehttps://redmine.ruby-lang.org/issues/126412016-08-01T10:30:38Zrovf (Ronald Fischer)ynnor@mm.st
<p>The documentation of the JSON stdlib class (i.e. <a href="http://ruby-doc.org/stdlib-2.2.5/libdoc/json/rdoc/JSON.html" class="external">http://ruby-doc.org/stdlib-2.2.5/libdoc/json/rdoc/JSON.html</a>) is missing a description, what the user has to do to provide JSON serialization for his own classes (i.e. description of the to_json and from_json callback is missing).</p> Ruby master - Bug #12468 (Closed): Logger: Can not rotate (log shifting failed. closed stream)https://redmine.ruby-lang.org/issues/124682016-06-07T12:13:27Zrovf (Ronald Fischer)ynnor@mm.st
<p>If I configure a Logger to rotate, by the time the logger is supposed to do the first rotation, it creates the new log file, but then hangs. When I abort the program using Control-C, I get an infinite series of error messages saying</p>
<pre><code>log shifting failed. closed stream
</code></pre>
<p>You can reproduce the error, if you run the attached example program on <strong>Windows</strong> (it could be a platform issue). The only prerequisite is that a subdirectory 'logs' must exist below the working directory.</p>
<p>I'm reporting error for the Cygwin version of Ruby. However, I found the nearly identical error also with JRuby 1.9.3, which suggests that the bug is likely in the Ruby stdlib code, and not in the specific port (i.e. Cygwin vs. JRuby). The main difference between the behaviour of the bug in Cygwin Ruby vs. JRuby is that aborting the program on JRuby does not produced the "log shifting...." error message.</p> Ruby master - Feature #12114 (Open): $VERBOSE = true is being ignoredhttps://redmine.ruby-lang.org/issues/121142016-02-26T11:18:06Zrovf (Ronald Fischer)ynnor@mm.st
<p>This programm correctly complains about "assigned but unused variable - p"</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="c1">#!/usr/bin/ruby -w</span>
<span class="nb">p</span><span class="o">=</span><span class="mi">1</span>
</code></pre>
<p>However, this one doesn't</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="c1">#!/usr/bin/ruby</span>
<span class="k">BEGIN</span> <span class="p">{</span><span class="vg">$VERBOSE</span> <span class="o">=</span> <span class="kp">true</span><span class="p">}</span>
<span class="nb">p</span><span class="o">=</span><span class="mi">1</span>
</code></pre>
<p>Setting <code>$VERBOSE</code> to true in a <code>BEGIN</code> block should have the same effect as providing it on the command line, but this is obviously not the case.</p> Ruby master - Misc #11584 (Closed): Kernel::loop silently catching StopIteration, should be docum...https://redmine.ruby-lang.org/issues/115842015-10-12T10:42:48Zrovf (Ronald Fischer)ynnor@mm.st
<p>The method Kernel::loop implicitly catches a StopIteration exception. This fact is documented on the documentation page for StopIteration, but it should also (and more importantly) be documented with the Kernel::loop method, because if one doesn't know this detail, the behaviour can be pretty surprising - see for example <a href="http://stackoverflow.com/questions/33040260/combining-raise-and-throw/" class="external">http://stackoverflow.com/questions/33040260/combining-raise-and-throw/</a>.</p> Ruby master - Feature #11550 (Open): Current behaviour of super(...) is dangerous in the presence...https://redmine.ruby-lang.org/issues/115502015-09-25T06:46:48Zrovf (Ronald Fischer)ynnor@mm.st
<p>Consider a class</p>
<pre><code> class C <P
include M1
include M2
def initialize
....
end
end
</code></pre>
<p>If P, M1 and M2 all provide a initialize method, and C::initialize calls super(...), the first initialize module in the chain, which has a formal parameter list matching the actual parameters in the super(....) call, is executed. The other ones are not executed. The following article demonstrates a clever way, how C::initialize can call all initializers of the included modules and of the parent class:</p>
<p>[[http://stdout.koraktor.de/blog/2010/10/13/ruby-calling-super-constructors-from-multiple-included-modules/]]</p>
<p>This solution works, but is complicated, and the reason is that the basic design of Ruby, with respect of initializing the base class, is flawed, for the following reason:</p>
<p>If we define an 'initialize' method, we certainly assume that its execution is necessary for the correct behaviour of our class or module. Therefore, the designer of a class or module should at least have the possibility to REQUIRE that initialize will be called (by a derived class), and the designer of a class which inherits from a parent class or includes a module, should have an EASY way to call all the parent initializers.</p>
<p>Here a first draft of how the language could be changed to meet this criterium; it's perhaps not the best design, but it might help clarifying my point:</p>
<p>(1) A class (or module) may define either a method initialize or a method initialize_strict (but not both). If it has initialize_strict defined, and the class where the module is included, respectively the class which inherits it, does NOT invoke this initializer, an exception is thrown, UNLESS initialize_strict can be called without parameters. In the latter case, it is always executed (even if no 'super' call is present).</p>
<p>(2) A class method super_of is added to class Object, with the prototype super_of(klass,arg*), where klass is a symbol or String or instance of type Class or Module. The affect of invoking super_of(:Foo,x,y) is identical to invoking initialize(x,y) in the ancestor class Foo. If Foo is neither a direct ancestor nor an included module, an exception is thrown.</p> Ruby master - Bug #10987 (Rejected): Warning "warning “regex literal in condition” issued, even c...https://redmine.ruby-lang.org/issues/109872015-03-20T13:22:36Zrovf (Ronald Fischer)ynnor@mm.st
<p>The following program emits the warning 'regex literal in condition':</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="c1">#!/usr/bin/ruby</span>
<span class="k">while</span> <span class="nb">gets</span>
<span class="nb">print</span> <span class="k">if</span> <span class="sr">/foo/</span><span class="o">..</span><span class="sr">/bar/</span>
<span class="k">end</span>
</code></pre>
<p>It seems that the parser does not recognize, that the "if" clause matches the regexp against $_</p>