Skip to content

class Crystal::TypeGuessVisitor
inherits Crystal::SemanticVisitor

Guess the type of class and instance variables from assignments to them.

Class methods

.new(mod, explicit_instance_vars : Hash(Type, Hash(String, TypeDeclarationWithLocation)), guessed_instance_vars : Hash(Type, Hash(String, InstanceVarTypeInfo)), initialize_infos : Hash(Type, Array(InitializeInfo)), instance_vars_outside : Hash(Type, Array(String)), errors : Hash(Type, Hash(String, Error)))

View source

Methods

#add_instance_var_type_info(vars, name, type : Type, node)

View source

#add_to_initialize_info(name)

View source

#add_type_info(vars, name, type, node)

View source

#args_hash

View source

#check_can_be_stored(node, type)

View source

#check_has_self(node)

View source

#check_var_is_self(node : Var)

View source

#current_type

At every point there's a current type. In the beginning this is the Program (top-level), but when a class definition is visited this changes to that type, and so on.

View source

#gather_returns(node)

View source

#guess_array_literal_element_types(node)

View source

#guess_from_two(type1, type2)

View source

#guess_hash_literal_key_value_types(node : HashLiteral)

View source

#guess_type(node : NilableCast)

View source

#guess_type(node : If)

View source

#guess_type(node : BinaryOp)

View source

#guess_type(node : InstanceVar)

View source

#guess_type(node : Var)

View source

#guess_type(node : UninitializedVar)

View source

#guess_type(node : TupleLiteral)

View source

#guess_type(node : Cast)

View source

#guess_type(node : Call)

View source

#guess_type(node : NamedTupleLiteral)

View source

#guess_type(node : RegexLiteral)

View source

#guess_type(node : Unless)

View source

#guess_type(node : Case)

View source

#guess_type(node : Path)

View source

#guess_type(node : Expressions)

View source

#guess_type(node : Assign)

View source

#guess_type(node : Not)

View source

#guess_type(node : IsA)

View source

#guess_type(node : RespondsTo)

View source

#guess_type(node : SizeOf)

View source

#guess_type(node : InstanceSizeOf)

View source

#guess_type(node : OffsetOf)

View source

#guess_type(node : Nop)

View source

#guess_type(node : ASTNode)

View source

#guess_type(node : RangeLiteral)

View source

#guess_type(node : HashLiteral)

View source

#guess_type(node : ArrayLiteral)

View source

#guess_type(node : SymbolLiteral)

View source

#guess_type(node : StringInterpolation)

View source

#guess_type(node : StringLiteral)

View source

#guess_type(node : NilLiteral)

View source

#guess_type(node : BoolLiteral)

View source

#guess_type(node : CharLiteral)

View source

#guess_type(node : NumberLiteral)

View source

#guess_type_call_lib_fun(node)

View source

#guess_type_call_lib_out(node : Call)

View source

#guess_type_call_pointer_malloc_two_args(node)

If it's Pointer.malloc(size, value), infer element type from value to T and then infer to Pointer(T)

View source

#guess_type_call_with_type_annotation(node)

Guess type from T.method, where T is a Path and method solves to a method with a type annotation (use the type annotation)

View source

#guess_type_from_method(obj_type, node : Call)

View source

#guess_type_from_method_impl(obj_type, node : Call)

View source

#guess_type_in_method_body(node : Expressions)

View source

#lookup_type?(node, root = nil)

View source

#lookup_type_no_check?(node)

View source

#lookup_type_var?(node, root = current_type)

View source

#process_assign(target, value)

View source

#process_assign(node : Assign)

View source

#process_assign_class_var(target, value)

View source

#process_assign_instance_var(target, value)

View source

#process_assign_instance_var(owner, target, value)

View source

#process_lib_out(owner, target, type)

View source

#process_multi_assign(node : MultiAssign)

View source

#process_uninitialized_instance_var(owner, target, value)

View source

#visit(node : TypeDeclaration)

View source

#visit(node : Def)

View source

#visit(node : Var)

View source

#visit(node : FunDef)

View source

#visit(node : ModuleDef)

View source

#visit(node : MultiAssign)

View source

#visit(node : ProcLiteral)

View source

#visit(node : MacroExpression)

View source

#visit(node : MacroIf)

View source

#visit(node : MacroFor)

View source

#visit(node : Assign)

View source

#visit(node : Call)

View source

#visit(node : ClassDef)

View source