Skip to content

Michelson compilation on view do not respect type declaration

This first contract:

type storage = int;

type parameter =
| ["Default"];

type return_ = [list <operation>, storage];

// @view
let basic = ([a,s]:[address, storage]): storage => s;

// @view
let not_funny = ([_,s]:[unit, storage]): storage => basic(Tezos.get_sender(),s);

// @view
let get_storage = ([_,s]:[unit, storage]): storage => s;

// @view
let get_address = ([_,s]:[unit, storage]): address => Tezos.get_sender();


const main = ([action, store] : [parameter, storage]) : return_ => {
 return [
   (list([]) as list <operation>),    // No operations
   (match (action, {
    Default:     ()  => 0}))
  ]
};

Compile to

{ parameter unit ;
  storage int ;
  code { DROP ; PUSH int 0 ; NIL operation ; PAIR } ;
  view "basic" address int { CDR } ;
  view "not_funny" address int { CDR } ;
  view "get_storage" unit int { CDR } ;
  view "get_address" unit int { CDR } }
  1. You can see that the type of not_funny changed, it have a address parameter in Michelson instead of unit in ligo I would expect either:
  • Compilation error cause Tezos.get_sender doesn't really make sense in a view
  • Compilation to view "not_funny" unit int { CDR }
  1. Michelson code of get_address seems wrong

This second contract

type storage = int;

type parameter =
| ["Default"];

type return_ = [list <operation>, storage];


// @view
let get_address = ([_,s]:[unit, storage]): address => Tezos.get_sender();


const main = ([action, store] : [parameter, storage]) : return_ => {
 return [
   (list([]) as list <operation>),    // No operations
   (match (action, {
    Default:     ()  => 0}))
  ]
};

compile to

{ parameter unit ;
  storage int ;
  code { DROP ; PUSH int 0 ; NIL operation ; PAIR } ;
  view "get_address" unit address { DROP ; SENDER } }

Here get_address looks as expected if we accept get_sender() in views