@@ -160,11 +160,6 @@ def __init__(self, name="Number", primitive=False):
160
160
super ().__init__ (name , primitive )
161
161
self .supertypes .append (ObjectType ())
162
162
163
- def is_assignable (self , other ):
164
- if isinstance (other , NumberLiteralType ):
165
- return False
166
- return isinstance (other , NumberType )
167
-
168
163
def box_type (self ):
169
164
return NumberType (self .name , primitive = False )
170
165
@@ -214,11 +209,6 @@ def __init__(self, name="String", primitive=False):
214
209
def box_type (self ):
215
210
return StringType (self .name , primitive = False )
216
211
217
- def is_assignable (self , other ):
218
- if isinstance (other , StringLiteralType ):
219
- return False
220
- return isinstance (other , StringType )
221
-
222
212
def get_name (self ):
223
213
if self .is_primitive :
224
214
return "string"
@@ -436,14 +426,22 @@ def __init__(self, types, name="UnionType", primitive=False):
436
426
def get_types (self ):
437
427
return self .types
438
428
439
- def is_assignable (self , other ):
440
- # TODO revisit this after implementing structural types
441
- return ( isinstance (other , UnionType ) and
442
- set ( other .types ) == set ( self . types ))
429
+ def is_subtype (self , other ):
430
+ if isinstance ( other , UnionType ):
431
+ return set ( self . types ). issubset (other . types )
432
+ return other .name == 'Object'
443
433
444
434
def get_name (self ):
445
435
return self .name
446
436
437
+ def __eq__ (self , other ):
438
+ return (self .__class__ == other .__class__ and
439
+ self .name == other .name and
440
+ set (self .types ) == set (other .types ))
441
+
442
+ def __hash__ (self ):
443
+ return hash (str (self .name ) + str (self .types ))
444
+
447
445
448
446
class UnionTypeFactory :
449
447
def __init__ (self , max_ut , max_in_union ):
@@ -470,15 +468,11 @@ def gen_union_type(self, gen):
470
468
Args:
471
469
num_of_types - Number of types to be unionized
472
470
gen - Instance of Hephaestus' generator
471
+
473
472
"""
474
473
num_of_types = self .get_number_of_types ()
475
474
assert num_of_types < len (self .candidates )
476
475
types = self .candidates .copy ()
477
- usr_types = [
478
- c .get_type ()
479
- for c in gen .context .get_classes (gen .namespace ).values ()
480
- ]
481
- types .extend (usr_types )
482
476
ut .random .shuffle (types )
483
477
types = types [0 :num_of_types ]
484
478
gen_union = UnionType (types )
0 commit comments