File tree Expand file tree Collapse file tree 2 files changed +14
-4
lines changed
src/main/ruby/truffleruby/core Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -41,6 +41,7 @@ Compatibility:
41
41
* Fix arity for ` Proc ` (#2098 , @ssnickolay )
42
42
* Check bounds for ` FFI::Pointer ` accesses when the size of the memory behind is known.
43
43
* Implement negative line numbers for eval (#1482 ).
44
+ * Avoid infinite recursion when redefining ` Warning#warn ` and calling ` Kernel#warn ` (#2109 ).
44
45
45
46
Performance:
46
47
Original file line number Diff line number Diff line change @@ -643,7 +643,7 @@ def untrace_var(name, cmd=undefined)
643
643
def warn ( *messages , uplevel : undefined )
644
644
if !Primitive . nil? ( $VERBOSE) && !messages . empty?
645
645
prefix = if Primitive . undefined? ( uplevel )
646
- + ''
646
+ ''
647
647
else
648
648
uplevel = Primitive . rb_to_int ( uplevel )
649
649
raise ArgumentError , "negative level (#{ uplevel } )" unless uplevel >= 0
@@ -662,13 +662,22 @@ def warn(*messages, uplevel: undefined)
662
662
if caller
663
663
"#{ caller . path } :#{ caller . lineno } : warning: "
664
664
else
665
- + 'warning: '
665
+ 'warning: '
666
666
end
667
667
end
668
668
669
- stringio = Truffle ::StringOperations ::SimpleStringIO . new ( prefix )
669
+ stringio = Truffle ::StringOperations ::SimpleStringIO . new ( + prefix )
670
670
Truffle ::IOOperations . puts ( stringio , *messages )
671
- Warning . warn ( stringio . string )
671
+ message = stringio . string
672
+
673
+ if Primitive . object_equal ( self , Warning ) # avoid recursion when redefining Warning#warn
674
+ unless message . encoding . ascii_compatible?
675
+ raise Encoding ::CompatibilityError , "ASCII incompatible encoding: #{ message . encoding } "
676
+ end
677
+ $stderr. write message
678
+ else
679
+ Warning . warn ( message )
680
+ end
672
681
end
673
682
nil
674
683
end
You can’t perform that action at this time.
0 commit comments