nim-lang / Nim

Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).
https://nim-lang.org
Other
16.61k stars 1.47k forks source link

C codegen error with `Option[lent int]` #15533

Open haxscramper opened 4 years ago

haxscramper commented 4 years ago

C codegen error when using Option[lent int]

Example

{.experimental: "views".}
import options
var a = [1, 2, 3, 4]
let o: Option[lent int] = some(a[0])

Current Output

Error: incompatible types when assigning to type ‘tyObject_Option__9bNiDL2UwApe2u9bmOJP4a9aw’ from type ‘tyObject_Option__Ryv9bNNePiiahF9b3Btk2KGA’
  169 |  o__vCNm9b4v9bUjkXuEJRVnKRSg = some__m1OjIFHE7x2EQs5RG5pOEAoptions(a__p9cXZaNbCqLkcGBblS5Wyrg[(((NI) 0))- 0]);
      |                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Error: execution of an external compiler program 'gcc -c  -w -fmax-errors=3   -I'/home/test/.choosenim/toolchains/nim-#devel/lib' -I/mnt/workspace/github/hax-nim/hack-test -o /home/test/.cache/nim/view_types_d/@mview_types.nim.c.o /home/test/.cache/nim/view_types_d/@mview_types.nim.c' failed with exit code: 1

Nim version

$ nim --version
Nim Compiler Version 1.3.7 [Linux: amd64]
Compiled at 2020-10-08
Copyright (c) 2006-2020 by Andreas Rumpf

active boot switches: -d:release
Araq commented 4 years ago

some(a[0]) produces an Option[int], not an Option[lent int], this should produce a type mismatch error.

arnetheduck commented 3 months ago

Option[lent int] would be nice though, with the associated lifetime tracking ;)