class Myst::TypeCheck::Scope

Defined in:

typecheck/scope.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(parent : Scope | Nil = nil, initial_capacity = nil) #

[View source]

Instance Method Detail

def [](key) #
Description copied from class Hash(String, Myst::TypeCheck::Type)

Returns the value for the key given by key. If not found, returns the default value given by Hash.new, otherwise raises KeyError.

h = {"foo" => "bar"}
h["foo"] # => "bar"

h = Hash(String, String).new("bar")
h["foo"] # => "bar"

h = Hash(String, String).new { "bar" }
h["foo"] # => "bar"

h = Hash(String, String).new
h["foo"] # raises KeyError

[View source]
def []=(key, value, always_create = false) #

[View source]
def []?(key) #
Description copied from class Hash(String, Myst::TypeCheck::Type)

Returns the value for the key given by key. If not found, returns nil. This ignores the default value set by Hash.new.

h = {"foo" => "bar"}
h["foo"]? # => "bar"
h["bar"]? # => nil

h = Hash(String, String).new("bar")
h["foo"]? # => nil

[View source]
def find_or_assign(key, new_value) #

[View source]
def merge!(other : Scope, *, unionize = true, nilify nil_type : Type | Nil = nil) #

Merge the entries of the given Scope into this one. If unionize is set to true, duplicate entries will be replaced in this scope with the union of both. If it is false, other will take precedence.

If nilify is set to true, and a given key is not present in both scopes, then the resulting type will be unioned with Nil in the merge.

nilify_left is similar to nilify, but only unions with Nil if the key does not exist in the left hand side.


[View source]
def parent : Scope | Nil #

def parent=(parent : Scope | Nil) #

[View source]
def parent? : Scope | Nil | Nil #