Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: "warn" with subclass of String constructed from heredoc #5935

Closed
buehmann opened this issue Oct 22, 2019 · 5 comments
Closed

TypeError: "warn" with subclass of String constructed from heredoc #5935

buehmann opened this issue Oct 22, 2019 · 5 comments
Milestone

Comments

@buehmann
Copy link

@buehmann buehmann commented Oct 22, 2019

Environment

$ jruby -v
jruby 9.2.8.0 (2.5.3) 2019-08-12 a1ac7ff OpenJDK 64-Bit Server VM 13+33 on 13+33 +jit [darwin-x86_64]
$ uname -a
Darwin mb204.fidor.loc 18.7.0 Darwin Kernel Version 18.7.0: Tue Aug 20 16:57:14 PDT 2019; root:xnu-4903.271.2~2/RELEASE_X86_64 x86_64 i386 MacBookPro15,1 Darwin

Expected Behavior

The script

S = Class.new(String)

warn S.new("foo")
warn S.new(<<M)
bar
M

is expected to output

foo
bar

to stderr.

Actual Behavior

Instead JRuby raises a TypeError for the second warning (heredoc case):

foo
TypeError: wrong argument type S (expected String)
    warn at org/jruby/common/RubyWarnings.java:224
  <main> at jruby-bug.rb:4

This was originally observed with the rainbow gem (https://github.com/sickill/rainbow) here: https://circleci.com/gh/rubocop-hq/rubocop/72166

@buehmann buehmann changed the title TypeError: "warn" with subclass of string constructed from heredoc TypeError: "warn" with subclass of String constructed from heredoc Oct 22, 2019
@enebo enebo added the parser label Oct 22, 2019
@enebo

This comment has been minimized.

Copy link
Member

@enebo enebo commented Oct 22, 2019

This seems to be a precedence problem in the parser. If I add a puts into that before that heredoc case it never prints. Likely this is a one word fix but will it be easy? :)

@enebo

This comment has been minimized.

Copy link
Member

@enebo enebo commented Oct 22, 2019

derp...this has nothing to do with parser. I just realized locally for me neither case works (I had put my puts between the two). Now for the twist! 9.2.8.0 the first case works???? In both cases these are strings so this is strange. Too strange to ignore for 9.2.9.0

@enebo enebo removed the parser label Oct 22, 2019
@enebo enebo added this to the JRuby 9.2.9.0 milestone Oct 22, 2019
@enebo

This comment has been minimized.

Copy link
Member

@enebo enebo commented Oct 22, 2019

Ok it took me longer to write my two comments then to actually figure this out. We were using a type check method which expects an exact match on warn argument being a String versus a kind-of String. Verifying something about protocol conversion before committing a fix.

@enebo enebo closed this in 26965b0 Oct 22, 2019
@enebo

This comment has been minimized.

Copy link
Member

@enebo enebo commented Oct 22, 2019

Circling back on why the first case stopped working since 9.2.8.0...@kares had recently added some kwargs support to warn and what changed happened to change both into hitting the same incorrect typeconverter type check (I believe it from no newline strings performing a strDup which made first call work but it is enough for me to know I fixed both with my commit).

@buehmann

This comment has been minimized.

Copy link
Author

@buehmann buehmann commented Oct 23, 2019

Thanks for the quick response! You're right: The important difference between the cases seems to be the trailing newline character, not the heredoc.

In 9.2.8.0:

warn S.new("foo\n")   # TypeError (wrong argument type S (expected String))
warn S.new(<<M.chomp) # works
bar
M
koic added a commit to koic/rubocop that referenced this issue Nov 8, 2019
Follow up of rubocop-hq@418973b.

jruby/jruby#5935 has been resolved and
JRuby 9.2.9.0 has been released.
@koic koic mentioned this issue Nov 8, 2019
5 of 8 tasks complete
koic added a commit to koic/rubocop that referenced this issue Nov 11, 2019
Follow up of rubocop-hq@418973b.

jruby/jruby#5935 has been resolved and
JRuby 9.2.9.0 has been released.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.