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

Calling super from a method in an included module can invoke the wrong superclass #3783

Closed
3 of 11 tasks
philr opened this issue Jan 23, 2018 · 3 comments
Closed
3 of 11 tasks

Comments

@philr
Copy link

philr commented Jan 23, 2018

  1. What command did you run?

I ran ruby rbx_strftime.rb, where rbx_strftime.rb is the following:

module Extension
  def strftime(format)    
    super('%Y')
  end
end

class ExtendedTime < Time
  include Extension
end

class ExtendedTime2 < Time
  include Extension
end

class TestClass
  def strftime(format)
    "TestClass: #{format}"
  end
end

class ExtendedTestClass < TestClass
  include Extension
end

puts ExtendedTime.new(2018).strftime('x')
puts ExtendedTime2.new(2018).strftime('x')
3.times { puts ExtendedTestClass.new.strftime('x') }
  1. What behavior did you expect?

I expected the following output:

2018
2018
TestClass: %Y
TestClass: %Y
TestClass: %Y
  1. What behavior did you get instead?

The third execution of puts ExtendedTestClass.new.strftime('x') resulted in a PrimitiveFailure exception being raised instead of the output of the last TestClass: %Y line (see https://gist.github.com/philr/b22784c46411a5b79dc53e57011f80f2#file-rbx_strftime_output-txt). The stack trace appears to indicate that the super call in Extension#strftime invoked Time#strftime instead of the expected TestClass#strftime.

  1. What version of Rubinius?

3.93

Output of rbx -v:

rubinius 3.93 (2.3.1 75512369 2018-01-20 4.0.0) [x86_64-linux-gnu]
  1. What version of operating system?

Ubuntu 17.04 (x86_64)

Output of uname -a:

Linux linuxdev 4.10.0-42-generic #46-Ubuntu SMP Mon Dec 4 14:38:01 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
  1. What is your operating system distribution, if your operating system has more than one?

Ubuntu 17.04

  1. How did you build your version of Rubinius?
  • I used RVM.
  • I used ruby-build.
  • I used ruby-install.
  • I built manually from a tarball.
  • I built manually from a git clone.
  • I installed a binary.
  1. Does this issue involve proprietary code?
  • Yes, this issue involves proprietary code that I cannot share.
  • Yes, this issue involves proprietary code, but I am able to share it under certain conditions.
  • No, this issue doesn't involve proprietary code.
  1. Are you able to help us debug the issue?
  • Yes, I'm able to help debug, including running commands under lldb.
  • No, I'm not able help debug or I don't have time to help.
@brixen
Copy link
Member

brixen commented Feb 9, 2018

@philr this is a pretty bizarre bug with a couple different aspects. I'm working on a fix now and hopefully will be done shortly. I'd be super curious how you reproduced it.

@brixen brixen closed this as completed in 985ac9e Feb 9, 2018
@philr
Copy link
Author

philr commented Feb 10, 2018

@brixen Thanks - I can confirm that this is now fixed with Rubinius 3.99.

I first spotted this issue running the tests for tzinfo on Rubinius 3.93 (see https://travis-ci.org/tzinfo/tzinfo/jobs/331588292#L539). The test code above is based on the LocalTime, LocalDateTime, LocalTimestamp and Localized types from tzinfo.

The tzinfo tests now pass on Rubinius 3.99 (https://travis-ci.org/tzinfo/tzinfo/jobs/339829915).

philr added a commit to tzinfo/tzinfo that referenced this issue Feb 10, 2018
The issue (rubinius/rubinius#3783) causing the
test failures has now been fixed.
@brixen
Copy link
Member

brixen commented Feb 10, 2018

@philr well, thanks for opening the issue and providing the repro, it was a huge help in fixing it! ❤️

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

No branches or pull requests

2 participants