From a37fb3ff9b24e50bb75a558433b26d333cbb3188 Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Fri, 19 Jan 2024 15:36:07 -0600 Subject: [PATCH] Update some warnings to deprecated This also marks syscall as not implemented (warns of pending deletion in CRuby) and modifies all RubyWarnings.warning* forms to no-op on verbose, as they used to (unsure when this changed). --- core/src/main/java/org/jruby/RubyArray.java | 2 +- core/src/main/java/org/jruby/RubyGlobal.java | 4 ++-- core/src/main/java/org/jruby/RubyIO.java | 9 +++++--- core/src/main/java/org/jruby/RubyKernel.java | 4 ++-- core/src/main/java/org/jruby/RubyModule.java | 2 +- core/src/main/java/org/jruby/RubyRegexp.java | 2 +- .../java/org/jruby/common/RubyWarnings.java | 22 ++++++++++++++++++- 7 files changed, 34 insertions(+), 11 deletions(-) diff --git a/core/src/main/java/org/jruby/RubyArray.java b/core/src/main/java/org/jruby/RubyArray.java index 106d60db6cc..a9e6adf2725 100644 --- a/core/src/main/java/org/jruby/RubyArray.java +++ b/core/src/main/java/org/jruby/RubyArray.java @@ -2210,7 +2210,7 @@ private IRubyObject getDefaultSeparator(Ruby runtime) { IRubyObject sep; sep = runtime.getGlobalVariables().get("$,"); if (!sep.isNil()) { - runtime.getWarnings().warn("$, is set to non-nil value"); + runtime.getWarnings().warningDeprecated("$, is set to non-nil value"); } return sep; } diff --git a/core/src/main/java/org/jruby/RubyGlobal.java b/core/src/main/java/org/jruby/RubyGlobal.java index c319f1caebc..bdfeebf5f56 100644 --- a/core/src/main/java/org/jruby/RubyGlobal.java +++ b/core/src/main/java/org/jruby/RubyGlobal.java @@ -829,13 +829,13 @@ public NonEffectiveGlobalVariable(Ruby runtime, String name, IRubyObject value) @Override public IRubyObject set(IRubyObject value) { - runtime.getWarnings().warn(ID.INEFFECTIVE_GLOBAL, "warning: variable " + name + " is no longer effective; ignored"); + runtime.getWarnings().warnDeprecated(ID.INEFFECTIVE_GLOBAL, "warning: variable " + name + " is no longer effective; ignored"); return value; } @Override public IRubyObject get() { - runtime.getWarnings().warn(ID.INEFFECTIVE_GLOBAL, "warning: variable " + name + " is no longer effective"); + runtime.getWarnings().warnDeprecated(ID.INEFFECTIVE_GLOBAL, "warning: variable " + name + " is no longer effective"); return value; } } diff --git a/core/src/main/java/org/jruby/RubyIO.java b/core/src/main/java/org/jruby/RubyIO.java index 28e94c572b4..60493cfe620 100644 --- a/core/src/main/java/org/jruby/RubyIO.java +++ b/core/src/main/java/org/jruby/RubyIO.java @@ -1819,6 +1819,7 @@ public static IRubyObject print(ThreadContext context, IRubyObject out, IRubyObj int i; IRubyObject line; int argc = args.length; + IRubyObject outputFS = runtime.getGlobalVariables().get("$,"); /* if no argument given, print `$_' */ if (argc == 0) { @@ -1826,8 +1827,10 @@ public static IRubyObject print(ThreadContext context, IRubyObject out, IRubyObj line = context.getLastLine(); args = new IRubyObject[]{line}; } + if (argc > 1 && !outputFS.isNil()) { + runtime.getWarnings().warnDeprecated("$, is set to non-nil value"); + } for (i=0; i0) { write(context, out, outputFS); } @@ -2403,7 +2406,7 @@ public IRubyObject close_on_exec_set(ThreadContext context, IRubyObject arg) { if (fptr == null || (fd = fptr.fd().realFileno) == -1 || !posix.isNative() || Platform.IS_WINDOWS ) { - runtime.getWarnings().warning("close_on_exec is not implemented on this platform for this stream type: " + fptr.fd().ch.getClass().getSimpleName()); + runtime.getWarnings().warningDeprecated("close_on_exec is not implemented on this platform for this stream type: " + fptr.fd().ch.getClass().getSimpleName()); return context.nil; } @@ -2858,7 +2861,7 @@ private static void warnWrite(final Ruby runtime, IRubyObject maybeIO) { } else { sep = '#'; } - runtime.getWarnings().warning(klass.toString() + sep + "write is outdated interface which accepts just one argument"); + runtime.getWarnings().warningDeprecated(klass.toString() + sep + "write is outdated interface which accepts just one argument"); } @JRubyMethod diff --git a/core/src/main/java/org/jruby/RubyKernel.java b/core/src/main/java/org/jruby/RubyKernel.java index c4aeaa95bc6..99d4b956dd9 100644 --- a/core/src/main/java/org/jruby/RubyKernel.java +++ b/core/src/main/java/org/jruby/RubyKernel.java @@ -1933,7 +1933,7 @@ public static RubyFixnum spawn(ThreadContext context, IRubyObject recv, IRubyObj return RubyProcess.spawn(context, recv, args); } - @JRubyMethod(required = 1, optional = 9, checkArity = false, module = true, visibility = PRIVATE) + @JRubyMethod(required = 1, optional = 9, checkArity = false, module = true, notImplemented = true, visibility = PRIVATE) public static IRubyObject syscall(ThreadContext context, IRubyObject recv, IRubyObject[] args) { throw context.runtime.newNotImplementedError("Kernel#syscall is not implemented in JRuby"); } @@ -2493,7 +2493,7 @@ public static IRubyObject nil_p(ThreadContext context, IRubyObject self) { // Writes backref due to decendant calls ending up in Regexp#=~ @JRubyMethod(name = "=~", writes = FrameField.BACKREF) public static IRubyObject op_match(ThreadContext context, IRubyObject self, IRubyObject arg) { - context.runtime.getWarnings().warn(ID.DEPRECATED_METHOD, + context.runtime.getWarnings().warnDeprecated(ID.DEPRECATED_METHOD, "deprecated Object#=~ is called on " + ((RubyBasicObject) self).type() + "; it always returns nil"); return ((RubyBasicObject) self).op_match(context, arg); diff --git a/core/src/main/java/org/jruby/RubyModule.java b/core/src/main/java/org/jruby/RubyModule.java index 2d71ff8dea6..d25f32b3c20 100644 --- a/core/src/main/java/org/jruby/RubyModule.java +++ b/core/src/main/java/org/jruby/RubyModule.java @@ -3000,7 +3000,7 @@ public IRubyObject attr(ThreadContext context, IRubyObject[] args) { Ruby runtime = context.runtime; if (args.length == 2 && (args[1] == runtime.getTrue() || args[1] == runtime.getFalse())) { - runtime.getWarnings().warning(ID.OBSOLETE_ARGUMENT, "optional boolean argument is obsoleted"); + runtime.getWarnings().warnDeprecated(ID.OBSOLETE_ARGUMENT, "optional boolean argument is obsoleted"); boolean writeable = args[1].isTrue(); RubySymbol sym = TypeConverter.checkID(args[0]); addAccessor(context, sym, getCurrentVisibilityForDefineMethod(context), args[0].isTrue(), writeable); diff --git a/core/src/main/java/org/jruby/RubyRegexp.java b/core/src/main/java/org/jruby/RubyRegexp.java index 417f2a9ab5f..0d38d2da104 100755 --- a/core/src/main/java/org/jruby/RubyRegexp.java +++ b/core/src/main/java/org/jruby/RubyRegexp.java @@ -934,7 +934,7 @@ public IRubyObject initialize_m(IRubyObject arg0, IRubyObject arg1, IRubyObject newOptions.setEncodingNone(true); return regexpInitialize(arg0.convertToString().getByteList(), ASCIIEncoding.INSTANCE, newOptions); } else { - metaClass.runtime.getWarnings().warn("encoding option is ignored - " + kcodeBytes); + metaClass.runtime.getWarnings().warnDeprecated("encoding option is ignored - " + kcodeBytes); } } return regexpInitializeString(arg0.convertToString(), newOptions); diff --git a/core/src/main/java/org/jruby/common/RubyWarnings.java b/core/src/main/java/org/jruby/common/RubyWarnings.java index 2f910627c23..cb8ce5ed1a8 100644 --- a/core/src/main/java/org/jruby/common/RubyWarnings.java +++ b/core/src/main/java/org/jruby/common/RubyWarnings.java @@ -191,6 +191,10 @@ public void warnDeprecated(ID id, String message) { if (runtime.getWarningCategories().contains(Category.DEPRECATED)) warn(id, message); } + public void warnDeprecated(String message) { + if (runtime.getWarningCategories().contains(Category.DEPRECATED)) warn(message); + } + public void warnDeprecatedAlternate(String name, String alternate) { if (runtime.getWarningCategories().contains(Category.DEPRECATED)) warn(ID.DEPRECATED_METHOD, name + " is deprecated; use " + alternate + " instead"); } @@ -208,26 +212,42 @@ public void warnOnce(ID id, String message) { } /** - * Verbose mode warning methods, their contract is that consumer must explicitly check for runtime.isVerbose() before calling them + * Verbose mode warning methods, only warn in verbose mode */ public void warning(String message) { warning(ID.MISCELLANEOUS, message); } + public void warningDeprecated(String message) { + warningDeprecated(ID.MISCELLANEOUS, message); + } + @Override public void warning(ID id, String message) { + if (!isVerbose()) return; + warn(id, message); } + public void warningDeprecated(ID id, String message) { + if (!isVerbose()) return; + + warnDeprecated(id, message); + } + /** * Prints a warning, only in verbose mode. */ @Override public void warning(ID id, String fileName, int lineNumber, String message) { + if (!isVerbose()) return; + warn(id, fileName, lineNumber, message); } public void warning(String fileName, int lineNumber, String message) { + if (!isVerbose()) return; + warn(fileName, lineNumber, message); }