ethereum/fe

Panics when returning structs which contains enum type

Y-Nak opened this issue · 0 comments

Y-Nak commented

What is wrong?

pub enum Accumulator {
    Zero
    Int(u32)
    Clo(i32, i32)
}

pub struct MyStruct {
    pub acc: Accumulator
    pub y: i32
    
    pub fn new() -> MyStruct { 
        return MyStruct(
            acc: Accumulator::Zero,
            y: 0
        )
    }
}

contract Bar {
    pub fn foo(self, ctx: Context) -> MyStruct {
        return MyStruct::new()
    }
}

causes a panic. Currently, #794 hide the panic, but when #794 is resolved, this panic will be revealed.

This panic is due to missing checks to ensure the types in contract function parameters are encodable, although it ensures those types are NOT enum.

How can it be fixed

Add a stopgap query to check if a type is encodable and use it. When the Encodable trait is implemented, then this query can be removed, and the check will be handled by a trait solver.