When the first argument is not a String (e.g. Regexp) and the second
is, areCompatible check swaps objects so that String is first.
However, JRuby also swapped encoding values, which is wrong — CRuby's
enc_compatible_latter (encoding.c) only swaps the object/isstr/idx
references but keeps enc1/enc2 derived from the original idx values
before the swap, so they retain the original argument order.
This caused Encoding.compatible?(regexp_eucjp, string_utf8) to
return EUC-JP instead of UTF-8 when the string was ASCII-only.
When the first argument is not a String (e.g. Regexp) and the second is, areCompatible check swaps objects so that String is first.
However, JRuby also swapped encoding values, which is wrong — CRuby's enc_compatible_latter (encoding.c) only swaps the object/isstr/idx references but keeps enc1/enc2 derived from the original idx values before the swap, so they retain the original argument order.
This caused Encoding.compatible?(regexp_eucjp, string_utf8) to return EUC-JP instead of UTF-8 when the string was ASCII-only.