I'm pleased to announce version 2.1.0 of RDL, a lightweight system for
adding types and contracts to Ruby. NOTE: With this version of RDL,
the annotations have moved into their own module, RDL::Annotate;
example just below.
Among other things, RDL can do *type checking*, meaning it can
"statically" check that a method body matches its type, as a way of
potentially detecting errors early in development. For example:
file.rb: require 'rdl' extend RDL::Annotate # new for RDL 2.1.0, need to add this to access `type` type '(Integer) -> Integer, typecheck: :now def id(x) "forty-two" end
$ ruby file.rb $ ruby file.rb .../lib/rdl/typecheck.rb:158:in `error': (RDL::Typecheck::StaticTypeError) .../file.rb:6:3: error: got type `String' where return type `Integer' expected .../file.rb:6: "forty-two" .../file.rb:6: ^~~~~~~~~~~
See README.md for a much longer discussion. A full list of changes are
below. Here are some of the key changes:
* Ruby 2.4 support.
* Annotations removed from Object, added to RDL::Annotate.
* Annotations also accessible via RDL module and RDL::RDLAnnotate
modules; see README.
* `o.type_cast(t)` now must be written `RDL.type_cast(o, t)` and
similarly with `instantiate!` and `deinstantiate!`.
* Many bugfixes.
Comments, questions, suggestions, and complaints are all welcome!
Email me or post on the forum.
* code/docs: https://github.com/plum-umd/rdl
* gem: https://rubygems.org/gems/rdl
* install: gem install rdl
* forum: https://groups.google.com/d/forum/rdl-users
- Type checking bug in const expressions when env[:self] is SingletonType
- Type for unary minus in numeric type files (changed :- to :-@)
- Type checking initialize method bugs
- Type checking of Module methods
- Type checking method when class name is included in type annotation
- Dynamic type checks after calls to instantiate!
- Ruby 2.4 compatibility!
- Various core and standard library types
- Parsing bug with `or`
- Sub-classes not wrapped bug
- Exception from case/when branch with empty body
- Support operator assignment when left-hand side has method args
- Support nested class names
- Type for unary plus in numeric type files
- Support for instantiate! for binding type parameters during static type
- New "check" flag for calls to instantiate! indicating whether we want to
check type of receiving object on call
- More precise static type checking for `Object#class` method
- Klass argument to rdl_nowrap, rdl_alias
- Some more support for Rails
- Support for next/break in block arguments
- Support for super in static analysis
- Global variables are now module variables of RDL::Globals
- at_exit handler only installed if `Config.report` or `.guess_types` are
- Subclass Parser::Diagnostic instead of monkey patching it
- Replaced `Fixnum` with `Integer` in README (suggested by
- All annotations removed from `Object` and added to `RDL::Annotate`
- `type_cast`, `instantiate!`, and `deinstantiate!` are now part of the
`RDL` module to avoid adding them to `Object`