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

The openArray view type example from the manual does not compile. #16848

Open
bobeff opened this issue Jan 27, 2021 · 0 comments
Open

The openArray view type example from the manual does not compile. #16848

bobeff opened this issue Jan 27, 2021 · 0 comments

Comments

@bobeff
Copy link
Contributor

bobeff commented Jan 27, 2021

The following example about the openArray view type from the manual does not compile.

Example

{.experimental: "views".}

proc take(a: openArray[int]) =
  echo a.len

proc main(s: seq[int]) =
  var x: openArray[int] = s # 'x' is a view into 's'
  # it is checked that 'x' does not outlive 's' and
  # that 's' is not mutated.
  for i in 0 .. high(x):
    echo x[i]
  take(x)
  
  take(x.toOpenArray(0, 1)) # slicing remains possible
  let y = x  # create a view from a view
  take y
  # it is checked that 'y' does not outlive 'x' and
  # that 'x' is not mutated as long as 'y' lives.

main(@[11, 22, 33])

Current Output

Error: 'y' borrows from location 'x' which does not live long enough

Expected Output

11
22
33
3
2
3

Compiler Version

$ nim -v
Nim Compiler Version 1.5.1 [Linux: amd64]
Compiled at 2021-01-27
Copyright (c) 2006-2021 by Andreas Rumpf

git hash: e1129749207d25597e81fe06cd7e3099b5ecb61e
active boot switches: -d:danger
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants