Class: Mirah::JVM::Types::NarrowingType

Inherits:
Object
  • Object
show all
Defined in:
lib/mirah/jvm/types/literals.rb

Overview

Represents a literal number that can be represented in multiple types

Direct Known Subclasses

FixnumLiteral, FloatLiteral

Instance Method Summary collapse

Constructor Details

#initialize(default_type, narrowed_type) ⇒ NarrowingType

Returns a new instance of NarrowingType.



23
24
25
26
# File 'lib/mirah/jvm/types/literals.rb', line 23

def initialize(default_type, narrowed_type)
  super(default_type)
  @narrowed = default_type != narrowed_type && narrowed_type
end

Instance Method Details

#hashObject



28
29
30
# File 'lib/mirah/jvm/types/literals.rb', line 28

def hash
  __getobj__.hash
end

#narrow!Object

Changes this type to the smallest type that will hold its literal value.



34
35
36
37
38
39
# File 'lib/mirah/jvm/types/literals.rb', line 34

def narrow!
  if @narrowed
    __setobj__(@narrowed)
    true
  end
end