Re: [vim/vim] Unreachable code after an if-else statement is not fully tested (PR #21407)

11 views
Skip to first unread message

h_east

unread,
Sep 30, 2026, 2:51:35 AM (yesterday) Sep 30
to vim/vim, Subscribed
h-east left a comment (vim/vim#21407)

@yegappan
The trailers below should be included in the commit message, not in the
Pull Request description.

Signed-off-by: Yegappan Lakshmanan
Assisted-by: GitHub Co-Pilot

As described in the 'Signing-off commits' section of CONTRIBUTING.md,
you can simply pass the -s option to git commit for Signed-off-by:.
On the other hand, Assisted-by: needs to be manually added to the
commit message (if you received assistance from AI).

—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/21407/c5905780991@github.com>

Yegappan Lakshmanan

unread,
Sep 30, 2026, 11:36:29 AM (24 hours ago) Sep 30
to vim/vim, Subscribed
yegappan left a comment (vim/vim#21407)

@yegappan The trailers below should be included in the commit message, not in the Pull Request description.

Signed-off-by: Yegappan Lakshmanan
Assisted-by: GitHub Co-Pilot

As described in the 'Signing-off commits' section of CONTRIBUTING.md, you can simply pass the -s option to git commit for Signed-off-by:. On the other hand, Assisted-by: needs to be manually added to the commit message (if you received assistance from AI).

Thanks. I have updated the commit message with these trailers.

—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/21407/c5914151735@github.com>

Yegappan Lakshmanan

unread,
Sep 30, 2026, 1:34:47 PM (22 hours ago) Sep 30
to vim/vim, Subscribed
yegappan left a comment (vim/vim#21407)

The following cases of unreachable code are not detected before this PR:

    vim9script
    # A nested if inside a for loop, where every branch either breaks,
    # continues or returns.
    def NestedBreakContinue(): number
      for i in [1, 2, 3]
        if i > 1
          if i == 2
            continue
          else
            break
          endif
        else
          return 10
        endif
        echo 'unreachable'
      endfor
      return 0
    enddef
    defcompile
    vim9script
    # break/return in an if-else make the code after the endif, inside the
    # loop body, unreachable.
    def BreakMakesFollowingCodeUnreachable(): number
      for i in [1, 2, 3]
        if i == 2
          break
        else
          return 10
        endif
        echo 'unreachable'
      endfor
      return 0
    enddef
    defcompile
    vim9script
    # Same as above but with "continue" instead of "break".
    def ContinueMakesFollowingCodeUnreachable(): number
      for i in [1, 2, 3]
        if i == 2
          continue
        else
          return 10
        endif
        echo 'unreachable'
      endfor
      return 0
    enddef
    defcompile
    vim9script
    # Both branches of the if-else "continue", so the loop body code after
    # the endif is unreachable.
    def BothBranchesContinue(): number
      for i in [1, 2, 3]
        if i == 2
          continue
        else
          continue
        endif
        echo 'unreachable'
      endfor
      return 0
    enddef
    defcompile
    vim9script
    # An if/elseif/else where each branch terminates differently: break,
    # continue and return.
    def BreakContinueReturnAllTerminate(): number
      for i in [1, 2, 3]
        if i == 1
          break
        elseif i == 2
          continue
        else
          return 10
        endif
        echo 'unreachable'
      endfor
      return 0
    enddef
    defcompile
    vim9script
    # In both branches, both the try and the (bare) catch throw.
    def TryCatchAllThrow(n: number)
      if n > 10
        try
          throw 'err_try_a'
        catch
          throw 'err_catch_a'
        endtry
      else
        try
          throw 'err_try_b'
        catch
          throw 'err_catch_b'
        endtry
      endif
      var x = 1
    enddef
    defcompile
    vim9script
    # Try/catch terminate via a mix of throw and return in each branch.
    def TryCatchMixedExits(n: number): string
      if n > 10
        try
          throw 'err'
        catch
          return 'handled'
        endtry
      else
        try
          return 'ok'
        catch
          throw 'unhandled'
        endtry
      endif
      var x = 1
      return 'a'
    enddef
    defcompile
    vim9script
    # Even if try/catch don't terminate, a return or throw in finally forces
    # termination.
    def TerminatedByFinally(n: number): string
      if n > 10
        try
          echo "no return here"
        catch
          echo "no return here either"
        finally
          return 'finally_a'
        endtry
      else
        try
          echo "no return"
        finally
          throw 'finally_b_err'
        endtry
      endif
      var x = 1
      return 'a'
    enddef
    defcompile
    vim9script
    # "finally" throwing overrides a try that returns.
    def FinallyThrowOverridesReturn(): string
      if true
        try
          return 'try'
        finally
          throw 'finally'
        endtry
      else
        return 'else'
      endif
      var x = 1
      return 'a'
    enddef
    defcompile
    vim9script
    # Both branches have a try/finally, where the try itself (not the
    # finally) terminates via return or throw.
    def TryBothBranches(n: number): string
      if n > 10
        try
          return 'a'
        finally
          echo 'done'
        endtry
      else
        try
          throw 'err'
        finally
          echo 'done'
        endtry
      endif
      return 'unreachable'
    enddef
    defcompile
    vim9script
    # A non-terminating finally does not prevent a return in the try from
    # terminating the overall construct.
    def ReturnWithNonTerminatingFinally(): string
      if true
        try
          return 'a'
        finally
          echo 'finally'
        endtry
      else
        return 'b'
      endif
      var x = 1
      return 'a'
    enddef
    defcompile

—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/21407/c5916407954@github.com>

Christian Brabandt

unread,
Sep 30, 2026, 3:05:05 PM (20 hours ago) Sep 30
to vim/vim, Subscribed
chrisbra left a comment (vim/vim#21407)

thanks

—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/21407/c5917814217@github.com>

Reply all
Reply to author
Forward
0 new messages