Class: LIT::TypeChecker Private

Inherits:
Object
  • Object
show all
Defined in:
lib/lit/type_checker.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.0

Constant Summary collapse

AST =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.0

Parser::AST
PRIMITIVE_TYPE_NAMESPACE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.0

"AST::Type::Primitive"

Instance Method Summary collapse

Constructor Details

#initialize(mod) ⇒ TypeChecker

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of TypeChecker.

Since:

  • 0.1.0



10
11
12
# File 'lib/lit/type_checker.rb', line 10

def initialize(mod)
  @mod = mod
end

Instance Method Details

#check_type!(type, value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.0



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/lit/type_checker.rb', line 14

def check_type!(type, value)
  is_primitive =
    if type.is_a?(Module)
      type.name.include?(PRIMITIVE_TYPE_NAMESPACE)
    else
      type.class.name.include?(PRIMITIVE_TYPE_NAMESPACE)
    end

  if is_primitive
    check_primitive_type!(type, value)
  elsif type.is_a?(AST::Type::Alias)
    check_type_alias!(type.name, value)
  else
    raise InvalidTypeError, "invalid type: #{type}"
  end
end