From 4d63582f7b0b11a3e272d8c2a0a12b209db53b65 Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Fri, 19 Jan 2024 16:14:24 -0600 Subject: [PATCH] These should be warn, not warning warning at some point started to warn all the time, even when not verbose. Previous commit modified this logic to match CRuby, with warning only producing output in verbose mode, but several specs and tests failed that expected that output. These cases should be warn, as in CRuby. --- core/src/main/java/org/jruby/Ruby.java | 2 +- core/src/main/java/org/jruby/RubyArray.java | 18 +++++++++--------- .../main/java/org/jruby/RubyEnumerable.java | 14 +++++++------- core/src/main/java/org/jruby/RubyModule.java | 4 ++-- .../java/org/jruby/lexer/yacc/RubyLexer.java | 10 +++++++--- .../java/org/jruby/parser/RubyParserBase.java | 4 ++-- .../java/org/jruby/util/StringSupport.java | 2 +- 7 files changed, 29 insertions(+), 25 deletions(-) diff --git a/core/src/main/java/org/jruby/Ruby.java b/core/src/main/java/org/jruby/Ruby.java index 9f4931b7390..6ab6cfd51fa 100644 --- a/core/src/main/java/org/jruby/Ruby.java +++ b/core/src/main/java/org/jruby/Ruby.java @@ -5608,7 +5608,7 @@ public RubyClass getData() { private final WarnCallback regexpWarnings = new WarnCallback() { @Override public void warn(String message) { - getWarnings().warning(message); + getWarnings().warn(message); } }; diff --git a/core/src/main/java/org/jruby/RubyArray.java b/core/src/main/java/org/jruby/RubyArray.java index a9e6adf2725..10831978892 100644 --- a/core/src/main/java/org/jruby/RubyArray.java +++ b/core/src/main/java/org/jruby/RubyArray.java @@ -645,7 +645,7 @@ public IRubyObject initialize(ThreadContext context, Block block) { unpack(); realLength = 0; if (block.isGiven() && context.runtime.isVerbose()) { - context.runtime.getWarnings().warning(ID.BLOCK_UNUSED, "given block not used"); + context.runtime.getWarnings().warn(ID.BLOCK_UNUSED, "given block not used"); } return this; } @@ -2210,7 +2210,7 @@ private IRubyObject getDefaultSeparator(Ruby runtime) { IRubyObject sep; sep = runtime.getGlobalVariables().get("$,"); if (!sep.isNil()) { - runtime.getWarnings().warningDeprecated("$, is set to non-nil value"); + runtime.getWarnings().warnDeprecated("$, is set to non-nil value"); } return sep; } @@ -2549,7 +2549,7 @@ public IRubyObject index(ThreadContext context, IRubyObject obj) { @JRubyMethod(name = {"index", "find_index"}) public IRubyObject index(ThreadContext context, IRubyObject obj, Block unused) { - if (unused.isGiven()) context.runtime.getWarnings().warning(ID.BLOCK_UNUSED, "given block not used"); + if (unused.isGiven()) context.runtime.getWarnings().warn(ID.BLOCK_UNUSED, "given block not used"); return index(context, obj); } @@ -2656,7 +2656,7 @@ public IRubyObject rindex(ThreadContext context, IRubyObject obj) { @JRubyMethod public IRubyObject rindex(ThreadContext context, IRubyObject obj, Block unused) { - if (unused.isGiven()) context.runtime.getWarnings().warning(ID.BLOCK_UNUSED, "given block not used"); + if (unused.isGiven()) context.runtime.getWarnings().warn(ID.BLOCK_UNUSED, "given block not used"); return rindex(context, obj); } @@ -3521,7 +3521,7 @@ public IRubyObject count(ThreadContext context, Block block) { @JRubyMethod(name = "count") public IRubyObject count(ThreadContext context, IRubyObject obj, Block block) { - if (block.isGiven()) context.runtime.getWarnings().warning(ID.BLOCK_UNUSED, "given block not used"); + if (block.isGiven()) context.runtime.getWarnings().warn(ID.BLOCK_UNUSED, "given block not used"); int n = 0; for (int i = 0; i < realLength; i++) { @@ -4929,7 +4929,7 @@ public IRubyObject all_pCommon(ThreadContext context, IRubyObject arg, Block blo boolean patternGiven = arg != null; if (block.isGiven() && patternGiven) { - context.runtime.getWarnings().warning(ID.BLOCK_UNUSED, "given block not used"); + context.runtime.getWarnings().warn(ID.BLOCK_UNUSED, "given block not used"); } if (!block.isGiven() || patternGiven) return all_pBlockless(context, arg); @@ -4972,7 +4972,7 @@ public IRubyObject any_pCommon(ThreadContext context, IRubyObject arg, Block blo boolean patternGiven = arg != null; if (block.isGiven() && patternGiven) { - context.runtime.getWarnings().warning(ID.BLOCK_UNUSED, "given block not used"); + context.runtime.getWarnings().warn(ID.BLOCK_UNUSED, "given block not used"); } if (!block.isGiven() || patternGiven) return any_pBlockless(context, arg); @@ -5014,7 +5014,7 @@ public IRubyObject none_pCommon(ThreadContext context, IRubyObject arg, Block bl boolean patternGiven = arg != null; if (block.isGiven() && patternGiven) { - context.runtime.getWarnings().warning(ID.BLOCK_UNUSED, "given block not used"); + context.runtime.getWarnings().warn(ID.BLOCK_UNUSED, "given block not used"); } if (!block.isGiven() || patternGiven) return none_pBlockless(context, arg); @@ -5056,7 +5056,7 @@ public IRubyObject one_pCommon(ThreadContext context, IRubyObject arg, Block blo boolean patternGiven = arg != null; if (block.isGiven() && patternGiven) { - context.runtime.getWarnings().warning(ID.BLOCK_UNUSED, "given block not used"); + context.runtime.getWarnings().warn(ID.BLOCK_UNUSED, "given block not used"); } if (!block.isGiven() || patternGiven) return one_pBlockless(context, arg); diff --git a/core/src/main/java/org/jruby/RubyEnumerable.java b/core/src/main/java/org/jruby/RubyEnumerable.java index 1718be70cc6..334a3468520 100644 --- a/core/src/main/java/org/jruby/RubyEnumerable.java +++ b/core/src/main/java/org/jruby/RubyEnumerable.java @@ -163,7 +163,7 @@ public static IRubyObject count(ThreadContext context, IRubyObject self, final I final Ruby runtime = context.runtime; final SingleInt result = new SingleInt(); - if (block.isGiven()) runtime.getWarnings().warning(ID.BLOCK_UNUSED , "given block not used"); + if (block.isGiven()) runtime.getWarnings().warn(ID.BLOCK_UNUSED , "given block not used"); each(context, eachSite(context), self, new JavaInternalBlockBody(runtime, context, "Enumerable#count", Signature.ONE_REQUIRED) { public IRubyObject yield(ThreadContext context1, IRubyObject[] args) { @@ -690,7 +690,7 @@ public static IRubyObject find_index(ThreadContext context, IRubyObject self, fi public static IRubyObject find_index(ThreadContext context, IRubyObject self, final IRubyObject cond, final Block block) { final Ruby runtime = context.runtime; - if (block.isGiven()) runtime.getWarnings().warning(ID.BLOCK_UNUSED , "given block not used"); + if (block.isGiven()) runtime.getWarnings().warn(ID.BLOCK_UNUSED , "given block not used"); if (self instanceof RubyArray) return ((RubyArray) self).find_index(context, cond); return find_indexCommon(context, eachSite(context), self, cond); @@ -1086,7 +1086,7 @@ public static IRubyObject inject(ThreadContext context, IRubyObject self, IRubyO public static IRubyObject inject(ThreadContext context, IRubyObject self, IRubyObject init, IRubyObject method, final Block block) { final Ruby runtime = context.runtime; - if (block.isGiven()) runtime.getWarnings().warning(ID.BLOCK_UNUSED , "given block not used"); + if (block.isGiven()) runtime.getWarnings().warn(ID.BLOCK_UNUSED , "given block not used"); final String methodId = method.asJavaString(); final SingleObject result = new SingleObject<>(init); @@ -1591,7 +1591,7 @@ public static IRubyObject none_pCommon(ThreadContext context, CallSite each, IRu final boolean patternGiven = pattern != null; if (block.isGiven() && patternGiven) { - context.runtime.getWarnings().warning(ID.BLOCK_UNUSED, "given block not used"); + context.runtime.getWarnings().warn(ID.BLOCK_UNUSED, "given block not used"); } try { @@ -1646,7 +1646,7 @@ public static IRubyObject one_pCommon(ThreadContext context, CallSite each, IRub final boolean patternGiven = pattern != null; if (block.isGiven() && patternGiven) { - context.runtime.getWarnings().warning(ID.BLOCK_UNUSED, "given block not used"); + context.runtime.getWarnings().warn(ID.BLOCK_UNUSED, "given block not used"); } try { @@ -1729,7 +1729,7 @@ public static IRubyObject all_pCommon(ThreadContext localContext, CallSite each, final boolean patternGiven = pattern != null; if (block.isGiven() && patternGiven) { - localContext.runtime.getWarnings().warning(ID.BLOCK_UNUSED, "given block not used"); + localContext.runtime.getWarnings().warn(ID.BLOCK_UNUSED, "given block not used"); } try { @@ -1819,7 +1819,7 @@ public static IRubyObject any_pCommon(ThreadContext localContext, CallSite site, final boolean patternGiven = pattern != null; if (block.isGiven() && patternGiven) { - localContext.runtime.getWarnings().warning(ID.BLOCK_UNUSED, "given block not used"); + localContext.runtime.getWarnings().warn(ID.BLOCK_UNUSED, "given block not used"); } try { diff --git a/core/src/main/java/org/jruby/RubyModule.java b/core/src/main/java/org/jruby/RubyModule.java index d25f32b3c20..0c24ff0f3bc 100644 --- a/core/src/main/java/org/jruby/RubyModule.java +++ b/core/src/main/java/org/jruby/RubyModule.java @@ -4912,9 +4912,9 @@ private IRubyObject setConstantCommon(String name, IRubyObject value, boolean hi if (notAutoload || !setAutoloadConstant(name, value, file, line)) { if (warn && notAutoload) { if (this.equals(getRuntime().getObject())) { - getRuntime().getWarnings().warning(ID.CONSTANT_ALREADY_INITIALIZED, "already initialized constant " + name); + getRuntime().getWarnings().warn(ID.CONSTANT_ALREADY_INITIALIZED, "already initialized constant " + name); } else { - getRuntime().getWarnings().warning(ID.CONSTANT_ALREADY_INITIALIZED, "already initialized constant " + this + "::" + name); + getRuntime().getWarnings().warn(ID.CONSTANT_ALREADY_INITIALIZED, "already initialized constant " + this + "::" + name); } } diff --git a/core/src/main/java/org/jruby/lexer/yacc/RubyLexer.java b/core/src/main/java/org/jruby/lexer/yacc/RubyLexer.java index 8b786bca75b..38e4331b6fc 100644 --- a/core/src/main/java/org/jruby/lexer/yacc/RubyLexer.java +++ b/core/src/main/java/org/jruby/lexer/yacc/RubyLexer.java @@ -162,6 +162,10 @@ private void warning(ID id, String file, int line, String message) { warnings.warning(id, file, line + 1, message); // rubysource-line is 0 based } + private void warn(ID id, String message) { + warnings.warn(id, getFile(), getRubySourceline(), message); + } + public enum Keyword { END ("end", new ByteList(new byte[] {'e', 'n', 'd'}, USASCII_ENCODING), keyword_end, keyword_end, EXPR_END), ELSE ("else", new ByteList(new byte[] {'e', 'l', 's', 'e'}, USASCII_ENCODING), keyword_else, keyword_else, EXPR_BEG), @@ -354,7 +358,7 @@ public int nextc() { c = '\n'; } else if (ruby_sourceline > last_cr_line) { last_cr_line = ruby_sourceline; - warning(ID.VOID_VALUE_EXPRESSION, "encountered \\r in middle of line, treated as a mere space"); + warn(ID.VOID_VALUE_EXPRESSION, "encountered \\r in middle of line, treated as a mere space"); } } @@ -1489,7 +1493,7 @@ private int dollar() { try { ref = Integer.parseInt(refAsString.substring(1)); } catch (NumberFormatException e) { - warning(ID.AMBIGUOUS_ARGUMENT, "`" + refAsString + "' is too big for a number variable, always nil"); + warn(ID.AMBIGUOUS_ARGUMENT, "`" + refAsString + "' is too big for a number variable, always nil"); ref = 0; } @@ -1531,7 +1535,7 @@ private int dot() { } if (parenNest == 0 && isLookingAtEOL()) { - warning(ID.MISCELLANEOUS, "... at EOL, should be parenthesized?"); + warn(ID.MISCELLANEOUS, "... at EOL, should be parenthesized?"); } else if (getLeftParenBegin() >= 0 && getLeftParenBegin() + 1 == parenNest) { if (isLexState(last_state, EXPR_LABEL)) { return tDOT3; diff --git a/core/src/main/java/org/jruby/parser/RubyParserBase.java b/core/src/main/java/org/jruby/parser/RubyParserBase.java index a5e1a36f934..75c3f99fdb9 100644 --- a/core/src/main/java/org/jruby/parser/RubyParserBase.java +++ b/core/src/main/java/org/jruby/parser/RubyParserBase.java @@ -1597,11 +1597,11 @@ public void warn(int line, String message) { // FIXME: Replace this with file/line version and stop using ISourcePosition public void warning(int line, String message) { - if (warnings.isVerbose()) warning(ID.USELESS_EXPRESSION, lexer.getFile(), line, message); + warning(ID.USELESS_EXPRESSION, lexer.getFile(), line, message); } public void warning(ID id, String file, int line, String message) { - warnings.warning(id, file, line + 1, message); // node/lexer lines are 0 based + warnings.warn(id, file, line + 1, message); // node/lexer lines are 0 based } // ENEBO: Totally weird naming (in MRI is not allocated and is a local var name) [1.9] diff --git a/core/src/main/java/org/jruby/util/StringSupport.java b/core/src/main/java/org/jruby/util/StringSupport.java index 8b1e9f81838..77bad8bcce8 100644 --- a/core/src/main/java/org/jruby/util/StringSupport.java +++ b/core/src/main/java/org/jruby/util/StringSupport.java @@ -2071,7 +2071,7 @@ public static IRubyObject rbStrEnumerateLines(RubyString str, ThreadContext cont if (wantarray) { // this code should be live in 3.0 if (false) { // #if STRING_ENUMERATORS_WANTARRAY - runtime.getWarnings().warning(ID.BLOCK_UNUSED, "given block not used"); + runtime.getWarnings().warn(ID.BLOCK_UNUSED, "given block not used"); } else { runtime.getWarnings().warning(ID.BLOCK_DEPRECATED, "passing a block to String#lines is deprecated"); wantarray = false;