Skip to content

Port TypeScript PR #58816: Use canHaveFlowNode in checkIfExpressionRefinesParameter#1132

Closed
Copilot wants to merge 2 commits intomainfrom
copilot/fix-1129
Closed

Port TypeScript PR #58816: Use canHaveFlowNode in checkIfExpressionRefinesParameter#1132
Copilot wants to merge 2 commits intomainfrom
copilot/fix-1129

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jun 9, 2025

This change ports TypeScript PR #58816 to the Go codebase, which improves flow node access safety in checkIfExpressionRefinesParameter.

Changes Made

Modified checkIfExpressionRefinesParameter in internal/checker/checker.go to use canHaveFlowNode before accessing flow nodes:

Before:

antecedent := getFlowNodeOfNode(expr)

After:

var antecedent *ast.FlowNode
if canHaveFlowNode(expr) {
    antecedent = getFlowNodeOfNode(expr)
}

Rationale

This change mirrors the TypeScript fix that replaced direct flow node access (expr.flowNode) with a safer pattern that first checks if the expression can have a flow node (canHaveFlowNode(expr) && expr.flowNode).

The Go equivalent makes the code more robust by:

  • Explicitly checking if a node can have a flow node before attempting to access it
  • Following the same defensive programming pattern as the upstream TypeScript change
  • Maintaining the same behavior while being more explicit about intent

Testing

  • All existing tests pass
  • Build completes successfully
  • No baseline changes required

Fixes #1129.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: andrewbranch <3277153+andrewbranch@users.noreply.github.com>
Copilot AI changed the title [WIP] Port TypeScript PR #58816: Use canHaveFlowNode in checkIfExpressionRefinesParameter Port TypeScript PR #58816: Use canHaveFlowNode in checkIfExpressionRefinesParameter Jun 9, 2025
Copilot AI requested a review from andrewbranch June 9, 2025 22:52
@jakebailey jakebailey deleted the copilot/fix-1129 branch June 24, 2025 23:56
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.

Port TypeScript PR #58816: Use canHaveFlowNode in checkIfExpressionRefinesParameter

2 participants