Class: Steep::Diagnostic::Ruby::IncompatibleAssignment

Inherits:
Base
  • Object
show all
Includes:
ResultPrinter
Defined in:
lib/steep/diagnostic/ruby.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#location, #node

Instance Method Summary collapse

Methods included from ResultPrinter

#detail_lines, #relation_message

Methods inherited from Base

#detail_lines, #diagnostic_code

Methods included from Helper

#error_name, #full_message

Constructor Details

#initialize(node:, lhs_type:, rhs_type:, result:) ⇒ IncompatibleAssignment

Returns a new instance of IncompatibleAssignment.



71
72
73
74
75
76
# File 'lib/steep/diagnostic/ruby.rb', line 71

def initialize(node:, lhs_type:, rhs_type:, result:)
  super(node: node)
  @lhs_type = lhs_type
  @rhs_type = rhs_type
  @result = result
end

Instance Attribute Details

#lhs_typeObject (readonly)

Returns the value of attribute lhs_type.



65
66
67
# File 'lib/steep/diagnostic/ruby.rb', line 65

def lhs_type
  @lhs_type
end

#resultObject (readonly)

Returns the value of attribute result.



67
68
69
# File 'lib/steep/diagnostic/ruby.rb', line 67

def result
  @result
end

#rhs_typeObject (readonly)

Returns the value of attribute rhs_type.



66
67
68
# File 'lib/steep/diagnostic/ruby.rb', line 66

def rhs_type
  @rhs_type
end

Instance Method Details

#header_lineObject



78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/steep/diagnostic/ruby.rb', line 78

def header_line
  node = node() or raise

  element = case node.type
            when :ivasgn, :lvasgn, :gvasgn, :cvasgn
              "a variable"
            when :casgn
              "a constant"
            else
              "an expression"
            end
  "Cannot assign a value of type `#{rhs_type}` to #{element} of type `#{lhs_type}`"
end