Skip to content

Commit

Permalink
These should be warn, not warning
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
headius committed Jan 19, 2024
1 parent a37fb3f commit ca4375f
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/Ruby.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};

Expand Down
18 changes: 9 additions & 9 deletions core/src/main/java/org/jruby/RubyArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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++) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
14 changes: 7 additions & 7 deletions core/src/main/java/org/jruby/RubyEnumerable.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<IRubyObject> result = new SingleObject<>(init);
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/RubyModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/parser/RubyParserBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/util/StringSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit ca4375f

Please sign in to comment.