Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow empty byte strings #914

Merged
merged 3 commits into from
Nov 24, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/base/Literal.ml
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,7 @@ module MkLiteral (T : ScillaType) = struct
raise @@ Invalid_argument "hex conversion: 0x prefix is missing"
else
let s_nopref = String.drop_prefix s 2 in
if String.length s_nopref = 0 then
raise @@ Invalid_argument "hex conversion: empty byte sequence"
else Hex.to_string (`Hex s_nopref)
Hex.to_string (`Hex s_nopref)

let hex_encoding bs = "0x" ^ Hex.show @@ Hex.of_string bs

Expand Down
2 changes: 1 addition & 1 deletion src/base/ScillaLexer.mll
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ let spid = ['_'] alphanum*
let cid = ['A'-'Z'] alphanum*
let tid = '\'' ['A'-'Z'] alphanum*
let hexdigit = ['a'-'f' 'A'-'F' '0'-'9']
let hex = '0' 'x' (hexdigit hexdigit)+
let hex = '0' 'x' (hexdigit hexdigit)*
let intty = "Int32" | "Int64" | "Int128" | "Int256" | "Uint32" |
"Uint64" | "Uint128" | "Uint256"

Expand Down
3 changes: 3 additions & 0 deletions tests/eval/good/builtin-eq-bystr.scilexp
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,7 @@ let res7 = builtin eq len1 len2 in

let res8 = andb res6 res7 in

let empty_bystrx = 0x in
let empty_bystr = builtin to_bystr empty_bystrx in

res8
6 changes: 4 additions & 2 deletions tests/eval/good/gold/builtin-eq-bystr.scilexp.gold
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
(True),
{ [res8 -> (True)],
{ [empty_bystr -> (ByStr 0x)],
[empty_bystrx -> (ByStr0 0x)],
[res8 -> (True)],
[res7 -> (True)],
[len2 -> (Uint32 2)],
[len1 -> (Uint32 2)],
Expand Down Expand Up @@ -27,4 +29,4 @@
[aa -> (ByStr 0x0f0f)],
[c -> (ByStr2 0x0f0f)],
[b -> (ByStr2 0xbfbf)] }
Gas remaining: 4001657
Gas remaining: 4001654
3 changes: 3 additions & 0 deletions tests/typecheck/good/builtin-eq-bystr.scilexp
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,7 @@ let res4 = andb res2 res3 in
let res5 = builtin eq ab ab2 in
let res6 = andb res4 res5 in

let empty_bystrx = 0x in
let empty_bystr = builtin to_bystr empty_bystrx in

res6
46 changes: 44 additions & 2 deletions tests/typecheck/good/gold/builtin-eq-bystr.scilexp.gold
Original file line number Diff line number Diff line change
Expand Up @@ -882,17 +882,59 @@
"column": 26
}
},
{
"vname": "empty_bystrx",
"type": "ByStr0",
"start_location": {
"file": "typecheck/good/builtin-eq-bystr.scilexp",
"line": 32,
"column": 5
},
"end_location": {
"file": "typecheck/good/builtin-eq-bystr.scilexp",
"line": 32,
"column": 17
}
},
{
"vname": "empty_bystr",
"type": "ByStr",
"start_location": {
"file": "typecheck/good/builtin-eq-bystr.scilexp",
"line": 33,
"column": 5
},
"end_location": {
"file": "typecheck/good/builtin-eq-bystr.scilexp",
"line": 33,
"column": 16
}
},
{
"vname": "empty_bystrx",
"type": "ByStr0",
"start_location": {
"file": "typecheck/good/builtin-eq-bystr.scilexp",
"line": 33,
"column": 36
},
"end_location": {
"file": "typecheck/good/builtin-eq-bystr.scilexp",
"line": 33,
"column": 48
}
},
{
"vname": "res6",
"type": "Bool",
"start_location": {
"file": "typecheck/good/builtin-eq-bystr.scilexp",
"line": 32,
"line": 35,
"column": 1
},
"end_location": {
"file": "typecheck/good/builtin-eq-bystr.scilexp",
"line": 32,
"line": 35,
"column": 5
}
}
Expand Down