pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/jruby/jruby/commit/97af910e65252321ec7e767c03135dac672ba212

" /> Fix covariant return type issues with to_s · jruby/jruby@97af910 · GitHub
Skip to content

Commit 97af910

Browse files
committed
Fix covariant return type issues with to_s
1 parent 844c151 commit 97af910

7 files changed

Lines changed: 34 additions & 12 deletions

File tree

core/src/main/java/org/jruby/RubyFile.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ public RubyString inspect(ThreadContext context) {
427427
ByteList str = new ByteList((path == null ? 4 : path.length()) + 8);
428428

429429
str.append('#').append('<');
430-
str.append(getMetaClass().getRealClass().to_s(context).getByteList());
430+
str.append(((RubyString) getMetaClass().getRealClass().to_s(context)).getByteList());
431431
str.append(':').append(path == null ? RubyNil.nilBytes : RubyEncoding.encodeUTF8(path));
432432
if (!openFile.isOpen()) str.append(CLOSED_MESSAGE);
433433
str.append('>');

core/src/main/java/org/jruby/RubyInteger.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -862,10 +862,17 @@ public IRubyObject denominator(ThreadContext context) {
862862
return RubyFixnum.one(context.runtime);
863863
}
864864

865+
@Deprecated(since = "10.0")
866+
public RubyString to_s() {
867+
return to_s(getCurrentContext());
868+
}
869+
870+
// Note: to not change interface by adding abstract method I made a base impl.
865871
@Override
866872
@JRubyMethod(name = {"to_s", "inspect"})
867-
public abstract RubyString to_s(ThreadContext context);
868-
873+
public RubyString to_s(ThreadContext context) {
874+
throw new RuntimeException("all numeric types must override this method");
875+
}
869876

870877
@Deprecated(since = "10.0")
871878
public RubyString to_s(IRubyObject x) {

core/src/main/java/org/jruby/RubyModule.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3243,11 +3243,16 @@ public RubyFixnum hash(ThreadContext context) {
32433243
return asFixnum(context, id);
32443244
}
32453245

3246+
@Override
3247+
public RubyString to_s() {
3248+
return (RubyString) to_s(getCurrentContext());
3249+
}
3250+
32463251
/** rb_mod_to_s
32473252
*
32483253
*/
32493254
@JRubyMethod(name = "to_s", alias = "inspect")
3250-
public RubyString to_s(ThreadContext context) {
3255+
public IRubyObject to_s(ThreadContext context) {
32513256
if (isSingleton()) {
32523257
IRubyObject attached = ((MetaClass) this).getAttached();
32533258
RubyString buffer = newString(context, "#<Class:");

core/src/main/java/org/jruby/RubyProcess.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,11 @@ public IRubyObject to_i(Ruby runtime) {
395395
return runtime.newFixnum(status);
396396
}
397397

398+
@Deprecated(since = "10.0")
399+
public IRubyObject to_s(Ruby runtime) {
400+
return to_s(getCurrentContext());
401+
}
402+
398403
@Override
399404
@JRubyMethod
400405
public IRubyObject to_s(ThreadContext context) {

core/src/main/java/org/jruby/RubyRegexp.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ public static IRubyObject union(ThreadContext context, IRubyObject recv, IRubyOb
848848
} else {
849849
hasAsciiOnly = true;
850850
}
851-
re = regex.to_s(context).getByteList();
851+
re = ((RubyString) regex.to_s(context)).getByteList();
852852
} else {
853853
RubyString str = e.convertToString();
854854
enc = str.getEncoding();
@@ -1441,6 +1441,11 @@ public IRubyObject inspect(ThreadContext context) {
14411441

14421442
private final static int EMBEDDABLE = RE_OPTION_MULTILINE|RE_OPTION_IGNORECASE|RE_OPTION_EXTENDED;
14431443

1444+
@Deprecated(since = "10.0")
1445+
public RubyString to_s() {
1446+
return to_s(getCurrentContext());
1447+
}
1448+
14441449
@Override
14451450
@JRubyMethod
14461451
public RubyString to_s(ThreadContext context) {

core/src/main/java/org/jruby/RubyString.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,15 +1327,10 @@ public static IRubyObject try_convert(ThreadContext context, IRubyObject recv, I
13271327
return str.checkStringType();
13281328
}
13291329

1330-
@Deprecated(since = "10.0")
1331-
public RubyString to_s() {
1332-
return (RubyString) to_s(getCurrentContext());
1333-
}
1334-
13351330
@SuppressWarnings("ReferenceEquality")
13361331
@JRubyMethod(name = {"to_s", "to_str"})
13371332
@Override
1338-
public IRubyObject to_s(ThreadContext context) {
1333+
public RubyString to_s(ThreadContext context) {
13391334
return metaClass.getRealClass() != stringClass(context) ? dupString(context, this) : this;
13401335
}
13411336

core/src/main/java/org/jruby/javasupport/JavaPackage.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,13 @@ public RubyString package_name(ThreadContext context) {
115115
return newString(context, packageName);
116116
}
117117

118+
@Deprecated(since = "10.0")
119+
public RubyString to_s() {
120+
return (RubyString) to_s(getCurrentContext());
121+
}
122+
118123
@Override
119-
public RubyString to_s(ThreadContext context) { return package_name(); }
124+
public IRubyObject to_s(ThreadContext context) { return package_name(); }
120125

121126
@JRubyMethod
122127
public IRubyObject inspect(ThreadContext context) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy