KEMBAR78
Fix infinite loop crash in variable type inference by MartinGC94 · Pull Request #25696 · PowerShell/PowerShell · GitHub
Skip to content

Conversation

@MartinGC94
Copy link
Contributor

PR Summary

Fixes a crash caused by an incorrect check with the IsWithin extension method. As the name suggests, it's supposed to check if an extent is within another extent but the check did not work properly. For example, suppose you have a PipelineAst like this: $Var1 | where {$true} and you want to check if $Var1 IsWithin that ast, the check would correctly return true. However, if you formatted it like this:

    $Var1 | where {
$true}

it would incorrectly return false because the end column of the PipelineAst is lower than the end column of the variable $Var1.

I've simplified the check to just look at the start and end offsets and it's now working as expected.
I'm not sure if a test is really needed since this is just a fix for an internal method that was simply wrong. But if it needs to be added I suppose I can just add a test like "It should not crash"

$Var1 = ls
$Var1 = $Var1 | where {
    $true
}
$Var1.<Tab>

PR Context

Fixes #25694

PR Checklist

Copy link
Collaborator

@SeeminglyScience SeeminglyScience left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember seeing this ages ago when I was first learning about the AST and thinking "that can't possibly work correctly"

Thanks for the fix Martin! ❤️ LGTM!

@SeeminglyScience SeeminglyScience added the CL-Engine Indicates that a PR should be marked as an engine change in the Change Log label Jun 30, 2025
@SeeminglyScience
Copy link
Collaborator

/azp run PowerShell-CI-linux-packaging, PowerShell-Windows-Packaging-CI

@azure-pipelines
Copy link

Azure Pipelines could not run because the pipeline triggers exclude this branch/path.

@SeeminglyScience SeeminglyScience merged commit 21f88b5 into PowerShell:master Jun 30, 2025
36 of 37 checks passed
@microsoft-github-policy-service
Copy link
Contributor

microsoft-github-policy-service bot commented Jun 30, 2025

📣 Hey @@MartinGC94, how did we do? We would love to hear your feedback with the link below! 🗣️

🔗 https://aka.ms/PSRepoFeedback

jobayer1V added a commit to jobayer1V/PowerShell that referenced this pull request Jul 6, 2025
Fix infinite loop crash in variable type inference (PowerShell#25696)
jobayer1V added a commit to jobayer1V/PowerShell that referenced this pull request Jul 12, 2025
jobayer1V added a commit to jobayer1V/PowerShell that referenced this pull request Jul 12, 2025
Revert "Fix infinite loop crash in variable type inference (PowerShell#25696)"
Amro1984 pushed a commit to Amro1984/PowerShell that referenced this pull request Aug 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-Engine Indicates that a PR should be marked as an engine change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Latest PowerShell build from main crashes on tab completion

2 participants