@@ -3158,6 +3158,18 @@ string YulUtilFunctions::allocateAndInitializeMemoryStructFunction(StructType co
31583158
31593159string YulUtilFunctions::conversionFunction (Type const & _from, Type const & _to)
31603160{
3161+ if (_from.category () == Type::Category::UserDefinedValueType)
3162+ {
3163+ solAssert (_from.isExplicitlyConvertibleTo (_to), " " );
3164+ solAssert (_to.isValueType (), " " );
3165+ return conversionFunction (dynamic_cast <UserDefinedValueTypeType const &>(_from).actualType (), _to);
3166+ }
3167+ if (_to.category () == Type::Category::UserDefinedValueType)
3168+ {
3169+ solAssert (_from.isExplicitlyConvertibleTo (_to), " " );
3170+ solAssert (_from.isValueType () || dynamic_cast <RationalNumberType const *>(&_from), " " );
3171+ return conversionFunction (_from, dynamic_cast <UserDefinedValueTypeType const &>(_to).actualType ());
3172+ }
31613173 if (_from.category () == Type::Category::Function)
31623174 {
31633175 solAssert (_to.category () == Type::Category::Function, " " );
@@ -3431,6 +3443,15 @@ string YulUtilFunctions::conversionFunction(Type const& _from, Type const& _to)
34313443 body = " converted := value" ;
34323444 break ;
34333445 }
3446+ case Type::Category::UserDefinedValueType:
3447+ {
3448+ auto & userDefinedValueTypeType = dynamic_cast <UserDefinedValueTypeType const &>(_from);
3449+ Type const * encodingType = userDefinedValueTypeType.encodingType ();
3450+ solAssert (encodingType, " " );
3451+ solAssert (_from == _to || *encodingType == _to, " " );
3452+ body = " converted := value" ;
3453+ break ;
3454+ }
34343455 default :
34353456 solAssert (false , " Invalid conversion from " + _from.canonicalName () + " to " + _to.canonicalName ());
34363457 }
@@ -3783,6 +3804,14 @@ string YulUtilFunctions::cleanupFunction(Type const& _type)
37833804 case Type::Category::InaccessibleDynamic:
37843805 templ (" body" , " cleaned := 0" );
37853806 break ;
3807+ case Type::Category::UserDefinedValueType:
3808+ templ (
3809+ " body" ,
3810+ " cleaned := " +
3811+ cleanupFunction (dynamic_cast <UserDefinedValueTypeType const &>(_type).actualType ()) +
3812+ " (value)"
3813+ );
3814+ break ;
37863815 default :
37873816 solAssert (false , " Cleanup of type " + _type.identifier () + " requested." );
37883817 }
@@ -3816,6 +3845,7 @@ string YulUtilFunctions::validatorFunction(Type const& _type, bool _revertOnFail
38163845 case Type::Category::Mapping:
38173846 case Type::Category::FixedBytes:
38183847 case Type::Category::Contract:
3848+ case Type::Category::UserDefinedValueType:
38193849 {
38203850 templ (" condition" , " eq(value, " + cleanupFunction (_type) + " (value))" );
38213851 break ;
0 commit comments