Skip to content

Structs are being mistranslated in some cases #302

Description

@machulen

Sample 1 - nested struct

pragma solidity ^0.5.0;

contract C {
	struct S {
		uint8 v;
	}
	struct T {
		S s;
	}
	function f() public {
		T memory t = T(S(25));
	}
}

Actual:

type c_S is record
  v : nat;
end;

type c_T is record
  s : t_S;
end;

type state is unit;

const c_S_default : c_S = record [ v = 0n ];

const c_T_default : c_T = record [ s = t_S_default ];

function f (const res__unit : unit) : (unit) is
  block {
    const t : c_T = record [ s = record [ v = 25n ] ];
  } with (unit);

Expected:

type c_S is record
  v : nat;
end;

type c_T is record
  s : c_S;
end;

type state is unit;

const c_S_default : c_S = record [ v = 0n ];

const c_T_default : c_T = record [ s = c_S_default ];

function f (const res__unit : unit) : (unit) is
  block {
    const t : c_T = record [ s = record [ v = 25n ] ];
  } with (unit);

Sample 2 - struct usage before definition

pragma solidity ^0.5.0;

contract C {
 function f() public {
   S memory s = S(25);
 }
 struct S {
   uint8 v;
 }
}

Actual: TypeError: Cannot read property 'scope' of undefined with a full stack trace.
Expected: some sensible Warning.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions