Class: Steep::TypeInference::MethodCall::Typed

Inherits:
Base
  • Object
show all
Defined in:
lib/steep/type_inference/method_call.rb

Direct Known Subclasses

Special

Instance Attribute Summary collapse

Attributes inherited from Base

#context, #method_name, #node, #receiver_type, #return_type

Instance Method Summary collapse

Methods inherited from Base

#with_return_type

Constructor Details

#initialize(node:, context:, method_name:, receiver_type:, actual_method_type:, method_decls:, return_type:) ⇒ Typed

Returns a new instance of Typed.



119
120
121
122
123
# File 'lib/steep/type_inference/method_call.rb', line 119

def initialize(node:, context:, method_name:, receiver_type:, actual_method_type:, method_decls:, return_type:)
  super(node: node, context: context, method_name: method_name, receiver_type: receiver_type, return_type: return_type)
  @actual_method_type = actual_method_type
  @method_decls = method_decls
end

Instance Attribute Details

#actual_method_typeObject (readonly)

Returns the value of attribute actual_method_type.



116
117
118
# File 'lib/steep/type_inference/method_call.rb', line 116

def actual_method_type
  @actual_method_type
end

#method_declsObject (readonly)

Returns the value of attribute method_decls.



117
118
119
# File 'lib/steep/type_inference/method_call.rb', line 117

def method_decls
  @method_decls
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



149
150
151
152
153
154
# File 'lib/steep/type_inference/method_call.rb', line 149

def ==(other)
  super &&
  other.is_a?(Typed) &&
    other.actual_method_type == actual_method_type &&
    other.method_decls == method_decls
end

#hashObject



158
159
160
# File 'lib/steep/type_inference/method_call.rb', line 158

def hash
  super ^ actual_method_type.hash ^ method_decls.hash
end

#pure?Boolean

Returns:



125
126
127
128
129
130
131
132
133
134
135
# File 'lib/steep/type_inference/method_call.rb', line 125

def pure?
  method_decls.all? do |method_decl|
    case member = method_decl.method_def.member
    when RBS::AST::Members::MethodDefinition
      member.annotations.any? {|annotation| annotation.string == "pure" }
    when RBS::AST::Members::Attribute
      # The attribute writer is not pure
      !method_decl.method_name.method_name.end_with?("=")
    end
  end
end

#update(node: self.node, return_type: self.return_type) ⇒ Object



137
138
139
140
141
142
143
144
145
146
147
# File 'lib/steep/type_inference/method_call.rb', line 137

def update(node: self.node, return_type: self.return_type)
  _ = self.class.new(
    node: node,
    return_type: return_type,
    context: context,
    method_name: method_name,
    receiver_type: receiver_type,
    actual_method_type: actual_method_type,
    method_decls: method_decls
  )
end