Support equality on bytes(N)
This commit is contained in:
parent
386419f112
commit
8a381e5ef1
@ -579,16 +579,30 @@ ast_binop(Op, Ann, {typed, _, A, Type}, B, Icode)
|
||||
_ when not Monomorphic ->
|
||||
gen_error({cant_compare_polymorphic_type, Ann, Op, Type});
|
||||
word -> #binop{op = Op, left = ast_body(A, Icode), right = ast_body(B, Icode)};
|
||||
string ->
|
||||
OtherType ->
|
||||
Neg = case Op of
|
||||
'==' -> fun(X) -> X end;
|
||||
'!=' -> fun(X) -> #unop{ op = '!', rand = X } end;
|
||||
_ -> gen_error({cant_compare, Ann, Op, Type})
|
||||
end,
|
||||
Neg(#funcall{ function = #var_ref{name = {builtin, str_equal}},
|
||||
args = [ast_body(A, Icode), ast_body(B, Icode)] });
|
||||
Args = [ast_body(A, Icode), ast_body(B, Icode)],
|
||||
Builtin =
|
||||
case OtherType of
|
||||
string ->
|
||||
#funcall{ function = #var_ref{name = {builtin, str_equal}},
|
||||
args = Args };
|
||||
{tuple, Types} ->
|
||||
case lists:usort(Types) of
|
||||
[word] ->
|
||||
#funcall{ function = #var_ref{name = {builtin, str_equal_p}},
|
||||
args = [ #integer{value = 32 * length(Types)} | Args] };
|
||||
_ -> gen_error({cant_compare, Ann, Op, Type})
|
||||
end;
|
||||
_ ->
|
||||
gen_error({cant_compare, Ann, Op, Type})
|
||||
end,
|
||||
Neg(Builtin)
|
||||
end;
|
||||
ast_binop('++', _, A, B, Icode) ->
|
||||
#funcall{ function = #var_ref{ name = {builtin, list_concat} },
|
||||
args = [ast_body(A, Icode), ast_body(B, Icode)] };
|
||||
|
@ -106,7 +106,8 @@ compilable_contracts() ->
|
||||
"include",
|
||||
"basic_auth",
|
||||
"bitcoin_auth",
|
||||
"address_literals"
|
||||
"address_literals",
|
||||
"bytes_equality"
|
||||
].
|
||||
|
||||
%% Contracts that should produce type errors
|
||||
|
18
test/contracts/bytes_equality.aes
Normal file
18
test/contracts/bytes_equality.aes
Normal file
@ -0,0 +1,18 @@
|
||||
|
||||
contract BytesEquality =
|
||||
|
||||
function eq16(a : bytes(16), b) = a == b
|
||||
function ne16(a : bytes(16), b) = a != b
|
||||
|
||||
function eq32(a : bytes(32), b) = a == b
|
||||
function ne32(a : bytes(32), b) = a != b
|
||||
|
||||
function eq47(a : bytes(47), b) = a == b
|
||||
function ne47(a : bytes(47), b) = a != b
|
||||
|
||||
function eq64(a : bytes(64), b) = a == b
|
||||
function ne64(a : bytes(64), b) = a != b
|
||||
|
||||
function eq65(a : bytes(65), b) = a == b
|
||||
function ne65(a : bytes(65), b) = a != b
|
||||
|
Loading…
x
Reference in New Issue
Block a user