33module RBS
44 module AST
55 class TypeParam
6- attr_reader :name , :variance , :location , :upper_bound_type , :default_type
6+ attr_reader :name , :variance , :location , :upper_bound_type , :lower_bound_type , : default_type
77
8- def initialize ( name :, variance :, upper_bound :, location :, default_type : nil , unchecked : false )
8+ def initialize ( name :, variance :, upper_bound :, lower_bound : , location :, default_type : nil , unchecked : false )
99 @name = name
1010 @variance = variance
1111 @upper_bound_type = upper_bound
12+ @lower_bound_type = lower_bound
1213 @location = location
1314 @default_type = default_type
1415 @unchecked = unchecked
@@ -21,6 +22,13 @@ def upper_bound
2122 end
2223 end
2324
25+ def lower_bound
26+ case lower_bound_type
27+ when Types ::ClassInstance , Types ::ClassSingleton , Types ::Interface
28+ lower_bound_type
29+ end
30+ end
31+
2432 def unchecked! ( value = true )
2533 @unchecked = value ? true : false
2634 self
@@ -35,14 +43,15 @@ def ==(other)
3543 other . name == name &&
3644 other . variance == variance &&
3745 other . upper_bound_type == upper_bound_type &&
46+ other . lower_bound_type == lower_bound_type &&
3847 other . default_type == default_type &&
3948 other . unchecked? == unchecked?
4049 end
4150
4251 alias eql? ==
4352
4453 def hash
45- self . class . hash ^ name . hash ^ variance . hash ^ upper_bound_type . hash ^ unchecked? . hash ^ default_type . hash
54+ self . class . hash ^ name . hash ^ variance . hash ^ upper_bound_type . hash ^ lower_bound_type . hash ^ unchecked? . hash ^ default_type . hash
4655 end
4756
4857 def to_json ( state = JSON ::State . new )
@@ -52,6 +61,7 @@ def to_json(state = JSON::State.new)
5261 unchecked : unchecked? ,
5362 location : location ,
5463 upper_bound : upper_bound_type ,
64+ lower_bound : lower_bound_type ,
5565 default_type : default_type
5666 } . to_json ( state )
5767 end
@@ -61,6 +71,10 @@ def map_type(&block)
6171 _upper_bound_type = yield ( b )
6272 end
6373
74+ if b = lower_bound_type
75+ _lower_bound_type = yield ( b )
76+ end
77+
6478 if dt = default_type
6579 _default_type = yield ( dt )
6680 end
@@ -69,6 +83,7 @@ def map_type(&block)
6983 name : name ,
7084 variance : variance ,
7185 upper_bound : _upper_bound_type ,
86+ lower_bound : _lower_bound_type ,
7287 location : location ,
7388 default_type : _default_type
7489 ) . unchecked! ( unchecked? )
@@ -108,6 +123,7 @@ def self.rename(params, new_names:)
108123 name : new_name ,
109124 variance : param . variance ,
110125 upper_bound : param . upper_bound_type &.map_type { |type | type . sub ( subst ) } ,
126+ lower_bound : param . lower_bound_type &.map_type { |type | type . sub ( subst ) } ,
111127 location : param . location ,
112128 default_type : param . default_type &.map_type { |type | type . sub ( subst ) }
113129 ) . unchecked! ( param . unchecked? )
@@ -136,6 +152,10 @@ def to_s
136152 s << " < #{ type } "
137153 end
138154
155+ if type = lower_bound_type
156+ s << " > #{ type } "
157+ end
158+
139159 if dt = default_type
140160 s << " = #{ dt } "
141161 end
0 commit comments