Skip to content

Commit 100b97f

Browse files
Prelude.lean: fix error on the length of Array.?pad (#4823)
This PR addresses a change not up-streamed in #4822, which implements (among others) the `«padRightBytes(_,_,_)_BYTES-HOOKED_Bytes_Bytes_Int_Int»` and `«padLeftBytes(_,_,_)_BYTES-HOOKED_Bytes_Bytes_Int_Int»` as `Array.rightpad` and `Array.leftpad` respectively. However, the length parameter passed to this functions was `Δ := len.toNat - b.size`, but it ought to be `len.toNat`, since these functions pad to the maximum of the length provided. Co-authored-by: automergerpr-permission-manager[bot] <190534181+automergerpr-permission-manager[bot]@users.noreply.github.com>
1 parent 8be1385 commit 100b97f

1 file changed

Lines changed: 2 additions & 4 deletions

File tree

  • pyk/src/pyk/klean/template/{{ cookiecutter.package_name }}/{{ cookiecutter.library_name }}

pyk/src/pyk/klean/template/{{ cookiecutter.package_name }}/{{ cookiecutter.library_name }}/Prelude.lean

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,16 +282,14 @@ Pads to the right `len - b.length` bytes with specified `val` value
282282
-/
283283
def «padRightBytes(_,_,_)_BYTES-HOOKED_Bytes_Bytes_Int_Int» (b : SortBytes) (len val : SortInt) : Option SortBytes :=
284284
if val < 0255 < val then none else
285-
let Δ := len.toNat - b.size
286-
some { data := (Array.rightpad Δ (⟨val.toNat⟩ : UInt8) b.data)}
285+
some { data := (Array.rightpad len.toNat (⟨val.toNat⟩ : UInt8) b.data)}
287286

288287
/--
289288
Pads to the left `len - b.length` bytes with specified `val` value
290289
-/
291290
def «padLeftBytes(_,_,_)_BYTES-HOOKED_Bytes_Bytes_Int_Int» (b : SortBytes) (len val : SortInt) : Option SortBytes :=
292291
if val < 0255 < val then none else
293-
let Δ := len.toNat - b.size
294-
some { data := (Array.leftpad Δ (⟨val.toNat⟩ : UInt8) b.data)}
292+
some { data := (Array.leftpad len.toNat (⟨val.toNat⟩ : UInt8) b.data)}
295293

296294
def «lengthBytes(_)_BYTES-HOOKED_Int_Bytes» (x0 : SortBytes) : Option SortInt :=
297295
Int.ofNat x0.size

0 commit comments

Comments
 (0)