Skip to content

Instantly share code, notes, and snippets.

@splattael
Last active September 16, 2016 12:57
Show Gist options
  • Save splattael/7b45e0f16e0084f50668 to your computer and use it in GitHub Desktop.
Save splattael/7b45e0f16e0084f50668 to your computer and use it in GitHub Desktop.
"self has wrong type to call super in this context" under weird circumstances
module ThreadSafe
class NonConcurrentCacheBackend
def self.method(key, value)
end
end
class MriCacheBackend < NonConcurrentCacheBackend
WRITE_LOCK = Mutex.new
def self.method(key, value)
WRITE_LOCK.synchronize { super }
end
end
end
module ActionView
module CompiledTemplates
end
Finalizer = proc do |mod|
proc do
mod.module_eval do
end
end
end
class Template
def self.compile!
new.compile!
end
def compile!
ObjectSpace.define_finalizer(self, Finalizer[ActionView::CompiledTemplates])
end
end
class PathResolver
def find_all
ThreadSafe::MriCacheBackend.method(:key, :value)
end
end
end
# Calling module_eval from the block inside the Finalizer proc should either raise an exception because
# wrong number of arguments, or call the block with source = identifier = line = nil.
# Instead,
# snafu.rb:11:in `block in []=': self has wrong type to call super in this context: ThreadSafe::MriCacheBackend (expected #<Class:ActionView::CompiledTemplates>) (TypeError)
# Also note that the behaviour is only triggered for many iterations.
# The behaviour is present in Ruby 2.3.0, not in 2.2.3
ActionView::CompiledTemplates.singleton_class.send :define_method, :module_eval do |_| # bug does not occur when |*|
# DO NOTHING
end
10000.times do
ActionView::PathResolver.new.find_all
ActionView::Template.compile!
end
@schnittchen
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment