Skip to content

borrow sealing doesn't work for borrows within objects #1456

Open
@alaviss

Description

@alaviss

Example

{.experimental: "views".}
type
  Mint = object
    data: int

  Option = object
    value: lent Mint

proc `=copy`(dst: var Mint, src: Mint) {.error.}

proc some(x: Mint): Option =
  Option(value: x)

proc main() =
  var x = Mint(data: 10)
  let optlent = some(x)

  echo $optlent.value
  x = Mint(data: 12)
  echo $optlent.value

main()

Actual Output

Compiles and run

Expected Output

Error that x cannot be modified because optlent is holding a live borrow.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcompiler/semRelated to semantic-analysis system of the compiler

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions