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

assertFalse: {.noreturn.} alternative to doAssert(false); safer than quit #13492

Closed
wants to merge 1 commit into from

Conversation

timotheecour
Copy link
Member

@timotheecour timotheecour commented Feb 25, 2020

    proc fun(a: string): int =
      case a
      of "foo": 1
      of "bar": 2
      of "bad1":
        doAssert false
        0 ## awkard, it requires specifying an `expr`, eg `default(typeof(result))`
      of "bad2": assertFalse() ## better; {.noreturn.} so no `expr` needed
      else: assertFalse(a)
    doAssertRaises(AssertionError): discard fun("bad")

note

this doesn't have any of the pitfalls of quit, see quit considered evil: bypasses defer and try/catch/finally which might do important cleanups - Nim forum

@timotheecour timotheecour changed the title assertFalse: {.noreturn.} alternative to doAssert(false) assertFalse: {.noreturn.} alternative to doAssert(false); safer than quit Feb 25, 2020
@Araq
Copy link
Member

Araq commented Feb 26, 2020

Maybe this should be called unreachable, but come on, almost nobody asked for this feature in a decade. If we add every little helper you think is nice to have, Nim would have a million of them, slowing down compile-times to the point where you're objectively more productive without them.

@Araq
Copy link
Member

Araq commented Feb 26, 2020

Cannot find a scenario where I am willing to accept this addition, so closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants