Skip to content

refactor(route): remove unreachable akind branch in backtrackToNextNodeKind - #1536

Open
lxcxjxhx wants to merge 1 commit into
cloudwego:mainfrom
lxcxjxhx:refactor/remove-unreachable-akind-branch
Open

refactor(route): remove unreachable akind branch in backtrackToNextNodeKind#1536
lxcxjxhx wants to merge 1 commit into
cloudwego:mainfrom
lxcxjxhx:refactor/remove-unreachable-akind-branch

Conversation

@lxcxjxhx

Copy link
Copy Markdown

What

Remove the dead if previous.kind == akind branch in backtrackToNextNodeKind() and simplify to nextNodeKind = previous.kind + 1.

Why

When backtracking from an akind node, previous.kind is always skind or pkind because entering an anyChild node always breaks the search loop immediately (line 447). The if previous.kind == akind branch was unreachable dead code.

Evidence:

  1. Control-flow analysis: The only path entering an akind node is at line 429-448, which always breaks immediately
  2. Runtime verification: Adding panic("unreachable") to the branch and running go test ./... passes without triggering
  3. History: This branch has existed since the early version of the file

Changes

  • tree.go: remove if previous.kind == akind branch, simplify to nextNodeKind = previous.kind + 1 (net -9 lines)

Testing

go test ./pkg/route/...

All existing tests pass. This is a pure refactor removing dead code.

Closes #1504

…deKind

When backtracking from an akind node, previous.kind is always skind or
pkind because entering an anyChild node always breaks the search loop
immediately. The `if previous.kind == akind` branch was dead code.

Simplifies the logic to `nextNodeKind = previous.kind + 1`.

Closes cloudwego#1504
@CLAassistant

CLAassistant commented Aug 23, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Question: Can previous.kind == akind be reached in backtrackToNextNodeKind()?

2 participants