RubyTypeInference

Contents


This page describes current state and future plan with regard to Type Inference in the NetBeans Ruby IDE. Search for Issues tokens for planned, currently unimplemented features.


Implemented in NetBeans 7.0

TODO: describe limitations


Implemented in NetBeans 6.5

Very basic Type Inference:

TODO: describe limitations


Individual Type Inference Features

Literals

TODO: describe current support and issues


Constructor

TODO: describe current support and issues


Variables

TODO: describe current support and issues


Constants

Built-in constants

Type awareness for built-in constants, like ARGV, RUBY_VERSION, ENV, TOPLEVEL_BINDING, ...

Image:built-in-constants_RubyTypeInference.png

Non-local constant:

Image:constant_RubyTypeInference.png

Local constant:

Image:constant_local_RubyTypeInference.png

TODO: describe current support and issues

Issues:

  • Issue 154600: Pre-generated stubs contains misleading values and thus misleading types are inferred for constants in Standard Ruby Library


Core Methods

Real Type Inference of classes/modules from Ruby Standard Library cannot be done by static code analysis of Ruby code, since they are written in native code, e.g. C or Java (Note: what about Rubinius?). Current approach utilized in NetBeans uses RDoc-based "Type Inference" which parses RDoc of such methods which often looks like:

class Module
  #     mod.ancestors -> array
  #
  #
  # Returns a list of modules included in <i>mod</i> (including
  # <i>mod</i> itself).
  #
  ....
  ....
  #
  def ancestors
    # This is just a stub for a builtin Ruby method.
    # See the top of this file for more info.
  end
end

from which we will parse Array return type. But not all methods contain such chunks of RDoc. There are more ways to handle them TODO.

In the future we might harness other approach, e.g. the one described in Static Type Inference for Ruby paper.


Methods

Methods chaining

greeting in example below is correctly inferred as the String type and code completion offers appropriate methods on the second line.

Image:methods_chain_assign_RubyTypeInference.png

TODO:

  • infer types of expression in broken AST, like
100.between?(0, 100).|
  • describe more of the current support and issues


Conditionals

TODO: describe current support and issues

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo