lib/steep/interface/builder.rb in steep-1.7.0 vs lib/steep/interface/builder.rb in steep-1.7.1
- old
+ new
@@ -7,12 +7,10 @@
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
-
- validate
end
def self.empty
new(self_type: nil, variable_bounds: {})
end
@@ -21,24 +19,30 @@
if self_type || class_type || instance_type
Substitution.build([], [], self_type: self_type, module_type: class_type, instance_type: instance_type)
end
end
- def validate
+ def validate_self_type
validate_fvs(:self_type, self_type)
+ end
+
+ def validate_instance_type
validate_fvs(:instance_type, instance_type)
+ end
+
+ def validate_class_type
validate_fvs(:class_type, class_type)
- self
end
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
@@ -85,15 +89,18 @@
end
def raw_shape(type, config)
case type
when AST::Types::Self
+ config.validate_self_type
self_type = config.self_type or raise
self_shape(self_type, config)
when AST::Types::Instance
+ config.validate_instance_type
instance_type = config.instance_type or raise
raw_shape(instance_type, config)
when AST::Types::Class
+ config.validate_class_type
klass_type = config.class_type or raise
raw_shape(klass_type, config)
when AST::Types::Name::Singleton
singleton_shape(type.name).subst(class_subst(type))
when AST::Types::Name::Instance