Skip to content

Commit

Permalink
Update some warnings to deprecated
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
headius committed Jan 19, 2024
1 parent d56f620 commit a37fb3f
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 11 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/RubyGlobal.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
9 changes: 6 additions & 3 deletions core/src/main/java/org/jruby/RubyIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -1819,15 +1819,18 @@ 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) {
argc = 1;
line = context.getLastLine();
args = new IRubyObject[]{line};
}
if (argc > 1 && !outputFS.isNil()) {
runtime.getWarnings().warnDeprecated("$, is set to non-nil value");
}
for (i=0; i<argc; i++) {
IRubyObject outputFS = runtime.getGlobalVariables().get("$,");
if (!outputFS.isNil() && i>0) {
write(context, out, outputFS);
}
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/RubyKernel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyRegexp.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
22 changes: 21 additions & 1 deletion core/src/main/java/org/jruby/common/RubyWarnings.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand All @@ -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);
}

Expand Down

0 comments on commit a37fb3f

Please sign in to comment.