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

Bug when using $stdout #1577

Closed
rbotafogo opened this issue Feb 7, 2019 · 2 comments
Closed

Bug when using $stdout #1577

rbotafogo opened this issue Feb 7, 2019 · 2 comments
Assignees
Labels
Milestone

Comments

@rbotafogo
Copy link
Contributor

rbotafogo commented Feb 7, 2019

Hello....

The following code works fine in MRI Ruby but crashes in Truffle:

    class Test
      def to_s
        puts "hello there"
      end
    end

    $stdout = StringIO.new
    t = Test.new
    puts t
    out = $stdout.string
    $stdout = STDOUT
    puts out
Failure/Error: write(DEFAULT_RECORD_SEPARATOR) unless line[-1] == ?\n

NoMethodError:
  undefined method `[]' for nil:NilClass
/home/rbotafogo/lib/graalvm-ce-1.0.0-rc12/jre/languages/ruby/lib/truffle/stringio.rb:412:in `block in puts'
/home/rbotafogo/lib/graalvm-ce-1.0.0-rc12/jre/languages/ruby/lib/truffle/stringio.rb:394:in `each'
/home/rbotafogo/lib/graalvm-ce-1.0.0-rc12/jre/languages/ruby/lib/truffle/stringio.rb:394:in `puts'
./specs/tmp.rb:38:in `puts'
./specs/tmp.rb:38:in `<top (required)>'
@aardvark179 aardvark179 self-assigned this Feb 12, 2019
@aardvark179
Copy link
Contributor

This appears to be happening because we don't have the same fallback behaviour as MRI when to_s doesn't return a string during StringIO#puts. I will submit a fix for this.

@aardvark179 aardvark179 added this to the 1.0.0-rc13 milestone Feb 20, 2019
@aardvark179
Copy link
Contributor

The fix for this has now been merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants