2424 has_dynamic_data ,
2525 is_base_type ,
2626)
27- from vyper .types .types import InterfaceType
28- from vyper .utils import (
29- DECIMAL_DIVISOR ,
30- GAS_IDENTITY ,
31- GAS_IDENTITYWORD ,
32- MemoryPositions ,
33- SizeLimits ,
34- )
27+ from vyper .utils import GAS_IDENTITY , GAS_IDENTITYWORD , MemoryPositions
3528
3629getcontext ().prec = 78 # MAX_UINT256 < 1e78
3730
@@ -342,7 +335,7 @@ def add_variable_offset(parent, key, pos, array_bounds_check=True):
342335 sub = LLLnode .from_list (["sha3" , ["add" , value , 32 ], key ])
343336 else :
344337 subtype = typ .valuetype
345- sub = base_type_conversion (key , key . typ , typ . keytype , pos = pos )
338+ sub = unwrap_location (key )
346339
347340 if sub is not None and location == "storage" :
348341 return LLLnode .from_list (["sha3_64" , parent , sub ], typ = subtype , location = "storage" )
@@ -378,42 +371,6 @@ def add_variable_offset(parent, key, pos, array_bounds_check=True):
378371 )
379372
380373
381- # Convert from one base type to another
382- @type_check_wrapper
383- def base_type_conversion (orig , frm , to , pos , in_function_call = False ):
384- orig = unwrap_location (orig )
385-
386- # do the base type check so we can use BaseType attributes
387- if not isinstance (frm , BaseType ) or not isinstance (to , BaseType ):
388- return
389-
390- if getattr (frm , "is_literal" , False ):
391- for typ in (frm .typ , to .typ ):
392- if typ in ("int128" , "uint256" ) and not SizeLimits .in_bounds (typ , orig .value ):
393- return
394-
395- is_decimal_int128_conversion = frm .typ == "int128" and to .typ == "decimal"
396- is_same_type = frm .typ == to .typ
397- is_literal_conversion = frm .is_literal and (frm .typ , to .typ ) == ("int128" , "uint256" )
398- is_address_conversion = isinstance (frm , InterfaceType ) and to .typ == "address"
399- if not (
400- is_same_type
401- or is_literal_conversion
402- or is_address_conversion
403- or is_decimal_int128_conversion
404- ):
405- return
406-
407- # handle None value inserted by `empty()`
408- if orig .value is None :
409- return LLLnode .from_list (0 , typ = to )
410-
411- if is_decimal_int128_conversion :
412- return LLLnode .from_list (["mul" , orig , DECIMAL_DIVISOR ], typ = BaseType ("decimal" ),)
413-
414- return LLLnode (orig .value , orig .args , typ = to , add_gas_estimate = orig .add_gas_estimate )
415-
416-
417374# Unwrap location
418375def unwrap_location (orig ):
419376 if orig .location == "memory" :
@@ -423,6 +380,9 @@ def unwrap_location(orig):
423380 elif orig .location == "calldata" :
424381 return LLLnode .from_list (["calldataload" , orig ], typ = orig .typ )
425382 else :
383+ # handle None value inserted by `empty`
384+ if orig .value is None :
385+ return LLLnode .from_list (0 , typ = orig .typ )
426386 return orig
427387
428388
@@ -548,9 +508,7 @@ def _make_array_index_setter(target, target_token, pos, location, offset):
548508def make_setter (left , right , location , pos , in_function_call = False ):
549509 # Basic types
550510 if isinstance (left .typ , BaseType ):
551- right = base_type_conversion (
552- right , right .typ , left .typ , pos , in_function_call = in_function_call ,
553- )
511+ right = unwrap_location (right )
554512 if location == "storage" :
555513 return LLLnode .from_list (["sstore" , left , right ], typ = None )
556514 elif location == "memory" :
0 commit comments