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

Code behaves different with and without --gc:arc #13465

Closed
StefanSalewski opened this issue Feb 22, 2020 · 3 comments
Closed

Code behaves different with and without --gc:arc #13465

StefanSalewski opened this issue Feb 22, 2020 · 3 comments

Comments

@StefanSalewski
Copy link

#from combinatorics import combinations

iterator combinations[T](a: openArray[T]; n: int): seq[T] = # stupid fake iterator
  var i = 0
  while i < len(a):
    var h: seq[T]
    h.setLen(0)
    for x in 0 .. n:
      h.add(a[i])
    yield h
    inc(i)

proc main =
  var unp: seq[int]
  block myb:
    unp = @[1, 2, 3]
    for t in unp.combinations(2):
      try:
        for k in t:
          echo k
          assert k != 1
        break myb
      except:
        echo "exception"

main()
$ nim c -r arcbug.nim 
/arcbug.nim; out: /home/stefan/gintrotest/tests/arcbug [SuccessX]
Hint: /home/stefan/gintrotest/tests/arcbug  [Exec]
1
exception
2
2
2

stefan@nuc ~/gintrotest/tests $ nim c --gc:arc -r arcbug.nim 
/arcbug.nim; out: /home/stefan/gintrotest/tests/arcbug [SuccessX]
Hint: /home/stefan/gintrotest/tests/arcbug  [Exec]
1
Traceback (most recent call last)
/home/stefan/gintrotest/tests/arcbug.nim(26) arcbug
/home/stefan/gintrotest/tests/arcbug.nim(21) main
/home/stefan/Nim/lib/system/assertions.nim(27) failedAssertImpl
/home/stefan/Nim/lib/system/assertions.nim(20) raiseAssert
/home/stefan/Nim/lib/system/fatal.nim(45) sysFatal
/home/stefan/Nim/lib/system/fatal.nim(33) sysFatal
Error: unhandled exception: /home/stefan/gintrotest/tests/arcbug.nim(21, 18) `k != 1`  [AssertionError]
Error: execution of an external program failed: '/home/stefan/gintrotest/tests/arcbug '

stefan@nuc ~/gintrotest/tests $ nim -v
Nim Compiler Version 1.1.1 [Linux: amd64]
Compiled at 2020-02-21
Copyright (c) 2006-2019 by Andreas Rumpf

git hash: 3667fd9f426eac968c326b3dc9571b7b7e8fef67
active boot switches: -d:release
@timotheecour
Copy link
Member

timotheecour commented Mar 6, 2020

looks like a duplicate of #13585 which was closed

This is the documented behaviour of --goto:exceptions and hence not a bug. I know it's disliked by many but that doesn't make it a bug.

IMO this will cause real problems when migrating to --gc:arc, and prevents code testability based on doAssertRaises + other things I mentioned in that issue, so we should simply have a compiler flag --catchdefects:on/off to control whether or not Defects (like AssectionError, IndexError etc) are allowed to be caught with --goto:exceptions (implied by --gc:arc)

@Araq
Copy link
Member

Araq commented Mar 10, 2020

We're adding catchdefects:on/off but closing for now.

@timotheecour
Copy link
Member

nim c --gc:arc -r arcbug.nim now works like nim c -r arcbug.nim, removing wontfix label

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

4 participants