Class: RDL::Type::DependentArgType

Inherits:
Type show all
Defined in:
lib/rdl/types/dependent_arg.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Type

#canonical, leq, #nil_type?, #optional?, #to_contract, #vararg?

Constructor Details

#initialize(name, type, predicate) ⇒ DependentArgType

Returns a new instance of DependentArgType.

Raises:

  • (RuntimeError)


9
10
11
12
13
14
15
16
# File 'lib/rdl/types/dependent_arg.rb', line 9

def initialize(name, type, predicate)
  @name = name
  @type = type
  @predicate = predicate
  raise RuntimeError, "Attempt to create annotated type with non-type" unless type.is_a? Type
  raise RuntimeError, "Attempt to create doubly annotated type" if (type.is_a? AnnotatedArgType) || (type.is_a? DependentArgType)
  super()
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/rdl/types/dependent_arg.rb', line 5

def name
  @name
end

#predicateObject (readonly)

Returns the value of attribute predicate.



7
8
9
# File 'lib/rdl/types/dependent_arg.rb', line 7

def predicate
  @predicate
end

#typeObject (readonly)

Returns the value of attribute type.



6
7
8
# File 'lib/rdl/types/dependent_arg.rb', line 6

def type
  @type
end

Instance Method Details

#<=(other) ⇒ Object

ignore refinement in comparison for now



40
41
42
# File 'lib/rdl/types/dependent_arg.rb', line 40

def <=(other)
  return @type <= other
end

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

:nodoc:



22
23
24
25
26
# File 'lib/rdl/types/dependent_arg.rb', line 22

def ==(other) # :nodoc:
  return false if other.nil?
  other = other.canonical
  return (other.instance_of? DependentArgType) && (other.name == @name) && (other.type == @type)
end

#copyObject



60
61
62
# File 'lib/rdl/types/dependent_arg.rb', line 60

def copy
  return DependentArgType.new(@name, @type.copy, @predicate)
end

#hashObject

:nodoc:



35
36
37
# File 'lib/rdl/types/dependent_arg.rb', line 35

def hash # :nodoc:
  return (57 + @name.hash) * @type.hash
end

#instantiate(inst) ⇒ Object



52
53
54
# File 'lib/rdl/types/dependent_arg.rb', line 52

def instantiate(inst)
  return DependentArgType.new(@name, @type.instantiate(inst), @predicate)
end

#leq_inst(other, inst = nil, ileft = true) ⇒ Object



44
45
46
# File 'lib/rdl/types/dependent_arg.rb', line 44

def leq_inst(other, inst=nil, ileft=true)
  return @type.leq_inst(other, inst, ileft)
end

#match(other) ⇒ Object

match on the base type, ignoring refinement



31
32
33
# File 'lib/rdl/types/dependent_arg.rb', line 31

def match(other)
  return @type.match(other)
end

#member?(obj, *args) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/rdl/types/dependent_arg.rb', line 48

def member?(obj, *args)
  return @type.member?(obj, *args)
end

#to_sObject



18
19
20
# File 'lib/rdl/types/dependent_arg.rb', line 18

def to_s
  return "#{@type.to_s} #{@name} {{#{@predicate}}}"
end

#widenObject



56
57
58
# File 'lib/rdl/types/dependent_arg.rb', line 56

def widen
  return DependentArgType.new(@name, @type.widen, @predicate)
end