tupl-tufts / rdl

Types, type checking, and contracts for Ruby
BSD 3-Clause "New" or "Revised" License
602 stars 38 forks source link

Can't handle RDL.type for deferred contract #39

Open ptarjan opened 7 years ago

ptarjan commented 7 years ago

If we don't want to pollute the global namespace, is there a way to annotate methods using the deferred syntax? The obvious thing didn't work:

$ cat /tmp/file.rb
require 'rdl'

RDL.type '() -> NilClass'
def foo; end
$ ruby /tmp/file.rb
/Users/pt/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rdl-2.1.0/lib/rdl/wrap.rb:213:in `block in do_method_added': Deferred type contract from class RDL being applied in class Object to foo (RuntimeError)
    from /Users/pt/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rdl-2.1.0/lib/rdl/wrap.rb:206:in `each'
    from /Users/pt/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rdl-2.1.0/lib/rdl/wrap.rb:206:in `do_method_added'
    from /Users/pt/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rdl-2.1.0/lib/rdl/wrap.rb:623:in `method_added'
    from /tmp/file.rb:4:in `<main>'
rmosolgo commented 6 years ago

:+1: for an alternative to the global namespace!

The other alternative I thought of was ... refinements 😱 !