Project

General

Profile

Actions

Bug #16522

closed

Ruby 2.7 logs deprecation warning when Warning[:deprecated] is set to false.

Added by snehasomwanshi@gmail.com (Sneha Somwanshi) about 4 years ago. Updated about 3 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:96969]

Description

Hi

While upgrading our monolithic app to ruby 2.7, we realised that ruby 2.7 is not suppressing all deprecation warnings.

Here is the test case:

~/dev/freeagent (ruby_2_7_0 *%) $ ruby -W:no-deprecated -e 'require "json"; JSON::Ext::Parser.new("hello", {})'
-e:1: warning: Using the last argument as keyword parameters is deprecated

The warning is originating from https://github.com/ruby/ruby/blob/647ee6f091eafcce70ffb75ddf7e121e192ab217/class.c#L2054 and setting Warning[:deprecated] = false or RUBYOPT=-W:no-deprecated -W:no-experimental does not suppress this warning.


Files

scan-args-deprecated-warn-16522.patch (6.79 KB) scan-args-deprecated-warn-16522.patch jeremyevans0 (Jeremy Evans), 05/29/2020 04:54 PM
Actions #1

Updated by snehasomwanshi@gmail.com (Sneha Somwanshi) about 4 years ago

  • Description updated (diff)

Updated by jeremyevans0 (Jeremy Evans) about 4 years ago

This no longer applies to the master branch, as the warnings have been removed.

Fixing this in 2.7 could be challenging, as the function to deduplicate warnings is static in vm_args.c. That function would have to be made non-static at least. The function also requires access to ec and iseq, and while I think ec is possible to get access to, I'm not sure about iseq.

You can work around the issue using the warning gem and using Warning.dedup.

Updated by jeremyevans0 (Jeremy Evans) almost 4 years ago

I took another look at this and I think we can silence the deprecation warnings with -W:no-deprecated even if we can't deduplicate the warnings. Attached is a patch that implements this. I'm not sure if the approach in ruby.h is acceptable (rb_scan_args has both an unoptimized version in class.c and an optimized version in ruby.h).

Updated by nagachika (Tomoyuki Chikanaga) over 3 years ago

We are discussing on the deprecated warning category feature in 2.7.2 on #17000 too.
As these are keyword arguments warnings, these will be suppressed by default in 2.7.2 anyway.

Actions #5

Updated by nagachika (Tomoyuki Chikanaga) about 3 years ago

  • Backport changed from 2.5: DONTNEED, 2.6: DONTNEED, 2.7: REQUIRED to 2.5: DONTNEED, 2.6: DONTNEED, 2.7: DONTNEED
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0