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.



123
124
125
126
127
# File 'lib/steep/type_inference/method_call.rb', line 123

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.



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

def actual_method_type
  @actual_method_type
end

#method_declsObject (readonly)

Returns the value of attribute method_decls.



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

def method_decls
  @method_decls
end

Instance Method Details

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



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

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

#hashObject



164
165
166
# File 'lib/steep/type_inference/method_call.rb', line 164

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

#pure?Boolean

Returns:

  • (Boolean)


129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/steep/type_inference/method_call.rb', line 129

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

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



143
144
145
146
147
148
149
150
151
152
153
# File 'lib/steep/type_inference/method_call.rb', line 143

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