argotorg / solcore

experimental solidity compiler
13 stars 1 forks source link

Intermediate Variable Needed When Returning `Memory Bytes` #35

Open d-xo opened 1 month ago

d-xo commented 1 month ago

The following fails:

data Memory(t) = Memory(word);
data Bytes = Bytes;

function get_bytes() -> Memory(Bytes) {
  let ptr : word;
  assembly {
    ptr := mload(0x40)
  };
  return Memory(ptr);
}

with:

Types do not match: Bytes and b
 - in:function get_bytes () -> Memory(Bytes) {
   let ptr :: word ;
   assembly {
   {   ptr := mload(64)
   }
   }
   return Memory(ptr)
}

If I insert an intermediate variable with a type annotation, then typechecking passes:

data Memory(t) = Memory(word);
data Bytes = Bytes;

function get_bytes() -> Memory(Bytes) {
  let ptr : word;
  assembly {
    ptr := mload(0x40)
  };
  let mem : Memory(Bytes) = Memory(ptr);
  return mem;
}