Skip to content

A bug of @inline. #5813

@Mng12345

Description

@Mng12345

rescript version: 9.1.2 & 10.0.1
See the code in playground

type t = {
  data: Js.TypedArray2.Uint8Array.t,
  mutable p: int
}

@inline
let readNextByte = decoder => {
  decoder.data
  ->Js.TypedArray2.Uint8Array.unsafe_get({
    let p = decoder.p
    decoder.p = p + 1
    p
  })
}

@inline
let readNextTwoByte = decoder => {
  decoder->readNextByte->lor(decoder->readNextByte->lsl(8))
}

let decoder = {
  data: Js.TypedArray2.Uint8Array.fromLength(10),
  p: 0
}

// here may be a bug if use @inline
decoder->readNextTwoByte->ignore
assert (decoder.p === 2)

The decoder.p should be 2 but 1 in this example. I found this bug in my project and created this example.
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions