class

TypeEnv

Inherits CanError < Reference < Object

Constructors

new(log : Logger)
Source

Instance methods

check_overload_ambiguity(function : FunctionDef, overloads : Array(FunctionDef))

Emit a warning if one set of arguments may match multiple functions. This occurs if two functions have the same number of parameters and the type of each parameter is either a type variable or the same type

For now it just issues a warning, but in the future it may issue an error and disallow such ambiguities.

Source
check_trait_implementations(trait_claims : Array(TraitClaim))

For each "Type is Trait" ("extend" clauses and traits put directly on a type), check to make sure the trait itself is valid and that the required methods actually exist.

Source
eval_depth
Source
eval_depth=(eval_depth : Int32)
Source
eval_signature(ast_func : Ast::HasSignature) : Signature
Source
fill_out_type_info(items : Array(Ast::TopLevelItem))

evaluate all type nodes for the fields of structs and of enum variants also re-evaluate the type nodes of function parameters and return types

Source
function_defs

property implementations : ::Hash(Trait, Implements) = {} of Trait => Implements property trait_claims = [] of TraitClaim property ast_functions = {} of String => Array(Ast::Function) property external_functions = [] of Ast::ExternalFunction

Source
function_defs=(function_defs : Hash(String, Array(FunctionDef)))

property implementations : ::Hash(Trait, Implements) = {} of Trait => Implements property trait_claims = [] of TraitClaim property ast_functions = {} of String => Array(Ast::Function) property external_functions = [] of Ast::ExternalFunction

Source
generate_default_methods(trait_claims : Array(TraitClaim))

Before checking the trait claims, all missing methods must be implemented with their default implementation (if it exists). This must be done in a separate pass because a given trait implementation may rely on the default implementation of another trait defined later.

Source
get_function(name : String, loc : Location)
Source
log=(log : Logger)
Source
method_exists?(name : String, signature : Signature) : Bool
Source
method_exists?(method : MethodDef) : Bool

This method currently uses Signature#== to find signature. This means it is quite specific in what counts a match.

Source
ready_to_validate_types

property functions = {} of String => Array(Function)

Source
ready_to_validate_types=(ready_to_validate_types : Bool)

property functions = {} of String => Array(Function)

Source
register_function(ast_func : Ast::Function | Ast::ExternalFunction)
Source
register_function(function : FunctionDef)
Source
register_function(function : MethodDef)
Source
register_functions_and_constraints(items : Array(Ast::TopLevelItem)) : Array(TraitClaim)

A second pass over the list of AST declarations now adds the constraints to the type parameters by evaluating the trait nodes into Traits However, trait compliance is not yet validated at this point This pass also stores all "trait claims"; ie, wherever the developer has indicated a given type implements a given trait. These trait claims may be generic as well.

Source
register_nominal_types(items : Array(Ast::TopLevelItem))

This pass takes the AST of each type declaration and inserts it into the global map of type definitions @type_defs Each TypeDef has a name, 0 or more type parameters, and fields (if struct) or variants (if enum) However, at this stage, only the names of the type parameters are stored (no constraints yet, and no fields or variants)

Source
set_default_string_and_array_bases

This method is an alternative to the above to be used in testing

Source
set_string_and_array_bases

Store the typedefs of strings and arrays in the node classes for their associated literals for convenient production of their types. This avoids the need to always pass the TypeEnv when hir nodes tell their type to the type checker.

Source
trait_defs
Source
trait_defs=(trait_defs : Hash(String, TraitDef))
Source
type_check_functions

Starting with fn main, instantiate and check all functions used in the program

Source
type_check_program(items : Array(Ast::TopLevelItem))
Source
type_defs
Source
type_defs=(type_defs : Hash(String, TypeDefinition))
Source
upsert(func : FunctionDef)
Source

Nested types