Class: Steep::Interface::Builder::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/steep/interface/builder.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(self_type:, class_type: nil, instance_type: nil, variable_bounds:) ⇒ Config

Returns a new instance of Config.



7
8
9
10
11
12
# File 'lib/steep/interface/builder.rb', line 7

def initialize(self_type:, class_type: nil, instance_type: nil, variable_bounds:)
  @self_type = self_type
  @class_type = class_type
  @instance_type = instance_type
  @variable_bounds = variable_bounds
end

Instance Attribute Details

#class_typeObject (readonly)

Returns the value of attribute class_type.



5
6
7
# File 'lib/steep/interface/builder.rb', line 5

def class_type
  @class_type
end

#instance_typeObject (readonly)

Returns the value of attribute instance_type.



5
6
7
# File 'lib/steep/interface/builder.rb', line 5

def instance_type
  @instance_type
end

#self_typeObject (readonly)

Returns the value of attribute self_type.



5
6
7
# File 'lib/steep/interface/builder.rb', line 5

def self_type
  @self_type
end

#variable_boundsObject (readonly)

Returns the value of attribute variable_bounds.



5
6
7
# File 'lib/steep/interface/builder.rb', line 5

def variable_bounds
  @variable_bounds
end

Class Method Details

.emptyObject



14
15
16
# File 'lib/steep/interface/builder.rb', line 14

def self.empty
  new(self_type: nil, variable_bounds: {})
end

Instance Method Details

#substObject



18
19
20
21
22
# File 'lib/steep/interface/builder.rb', line 18

def subst
  if self_type || class_type || instance_type
    Substitution.build([], [], self_type: self_type, module_type: class_type, instance_type: instance_type)
  end
end

#upper_bound(a) ⇒ Object



52
53
54
# File 'lib/steep/interface/builder.rb', line 52

def upper_bound(a)
  variable_bounds.fetch(a, nil)
end

#validate_class_typeObject



32
33
34
# File 'lib/steep/interface/builder.rb', line 32

def validate_class_type
  validate_fvs(:class_type, class_type)
end

#validate_fvs(name, type) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/steep/interface/builder.rb', line 36

def validate_fvs(name, type)
  if type
    fvs = type.free_variables
    if fvs.include?(AST::Types::Self.instance)
      raise "#{name} cannot include 'self' type: #{type}"
    end
    if fvs.include?(AST::Types::Instance.instance)
      Steep.logger.fatal { "#{name} cannot include 'instance' type: #{type}" }
      raise "#{name} cannot include 'instance' type: #{type}"
    end
    if fvs.include?(AST::Types::Class.instance)
      raise "#{name} cannot include 'class' type: #{type}"
    end
  end
end

#validate_instance_typeObject



28
29
30
# File 'lib/steep/interface/builder.rb', line 28

def validate_instance_type
  validate_fvs(:instance_type, instance_type)
end

#validate_self_typeObject



24
25
26
# File 'lib/steep/interface/builder.rb', line 24

def validate_self_type
  validate_fvs(:self_type, self_type)
end