@@ -3258,68 +3258,52 @@ string YulUtilFunctions::conversionFunction(Type const& _from, Type const& _to)
3258
3258
switch (fromCategory)
3259
3259
{
3260
3260
case Type::Category::Address:
3261
+ case Type::Category::Contract:
3261
3262
body =
3262
3263
Whiskers (" converted := <convert>(value)" )
3263
3264
(" convert" , conversionFunction (IntegerType (160 ), _to))
3264
3265
.render ();
3265
3266
break ;
3266
3267
case Type::Category::Integer:
3267
3268
case Type::Category::RationalNumber:
3268
- case Type::Category::Contract:
3269
3269
{
3270
+ solAssert (_from.mobileType (), " " );
3270
3271
if (RationalNumberType const * rational = dynamic_cast <RationalNumberType const *>(&_from))
3271
- solUnimplementedAssert (!rational->isFractional (), " Not yet implemented - FixedPointType." );
3272
+ if (rational->isFractional ())
3273
+ solAssert (toCategory == Type::Category::FixedPoint, " " );
3274
+
3272
3275
if (toCategory == Type::Category::FixedBytes)
3273
3276
{
3274
- solAssert (
3275
- fromCategory == Type::Category::Integer || fromCategory == Type::Category::RationalNumber,
3276
- " Invalid conversion to FixedBytesType requested."
3277
- );
3278
3277
FixedBytesType const & toBytesType = dynamic_cast <FixedBytesType const &>(_to);
3279
3278
body =
3280
3279
Whiskers (" converted := <shiftLeft>(<clean>(value))" )
3281
- (" shiftLeft" , shiftLeftFunction (256 - toBytesType.numBytes () * 8 ))
3282
- (" clean" , cleanupFunction (_from))
3283
- .render ();
3280
+ (" shiftLeft" , shiftLeftFunction (256 - toBytesType.numBytes () * 8 ))
3281
+ (" clean" , cleanupFunction (_from))
3282
+ .render ();
3284
3283
}
3285
3284
else if (toCategory == Type::Category::Enum)
3286
- {
3287
- solAssert (_from.mobileType (), " " );
3288
3285
body =
3289
3286
Whiskers (" converted := <cleanEnum>(<cleanInt>(value))" )
3290
3287
(" cleanEnum" , cleanupFunction (_to))
3291
- // "mobileType()" returns integer type for rational
3292
- (" cleanInt" , cleanupFunction (*_from.mobileType ()))
3288
+ (" cleanInt" , cleanupFunction (_from))
3293
3289
.render ();
3294
- }
3295
3290
else if (toCategory == Type::Category::FixedPoint)
3296
3291
solUnimplemented (" Not yet implemented - FixedPointType." );
3297
- else if (toCategory == Type::Category::Address)
3292
+ else if (toCategory == Type::Category::Address || toCategory == Type::Category::Contract )
3298
3293
body =
3299
3294
Whiskers (" converted := <convert>(value)" )
3300
- (" convert" , conversionFunction (_from, IntegerType (160 )))
3301
- .render ();
3302
- else
3295
+ (" convert" , conversionFunction (_from, IntegerType (160 )))
3296
+ .render ();
3297
+ else if (toCategory == Type::Category::Integer)
3303
3298
{
3304
- solAssert (
3305
- toCategory == Type::Category::Integer ||
3306
- toCategory == Type::Category::Contract,
3307
- " " );
3308
- IntegerType const addressType (160 );
3309
- IntegerType const & to =
3310
- toCategory == Type::Category::Integer ?
3311
- dynamic_cast <IntegerType const &>(_to) :
3312
- addressType;
3299
+ IntegerType const & to = dynamic_cast <IntegerType const &>(_to);
3313
3300
3314
3301
// Clean according to the "to" type, except if this is
3315
3302
// a widening conversion.
3316
3303
IntegerType const * cleanupType = &to;
3317
- if (fromCategory != Type::Category::RationalNumber )
3304
+ if (fromCategory == Type::Category::Integer )
3318
3305
{
3319
- IntegerType const & from =
3320
- fromCategory == Type::Category::Integer ?
3321
- dynamic_cast <IntegerType const &>(_from) :
3322
- addressType;
3306
+ IntegerType const & from = dynamic_cast <IntegerType const &>(_from);
3323
3307
if (to.numBits () > from.numBits ())
3324
3308
cleanupType = &from;
3325
3309
}
@@ -3328,6 +3312,8 @@ string YulUtilFunctions::conversionFunction(Type const& _from, Type const& _to)
3328
3312
(" cleanInt" , cleanupFunction (*cleanupType))
3329
3313
.render ();
3330
3314
}
3315
+ else
3316
+ solAssert (false , " " );
3331
3317
break ;
3332
3318
}
3333
3319
case Type::Category::Bool:
0 commit comments