Skip to content

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

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

Closed
wants to merge 2 commits into from

Conversation

Copilot
Copy link
Contributor

@Copilot 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 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 Copilot AI requested a review from andrewbranch June 9, 2025 22:52
Copilot finished work on behalf of andrewbranch June 9, 2025 22:53
@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