Repository: PowerShell/PowerShell
File: src/System.Management.Automation/engine/CommandCompletion/CompletionAnalysis.cs (C#)

Code before:
                errorStatement = pipeline.Parent as ErrorStatementAst;
                if (errorStatement == null || errorStatement.Kind == null || errorStatement.Flags == null)
                {
                    return false;
                }

                return (errorStatement.Kind.Kind.Equals(TokenKind.Switch) &&
                        errorStatement.Flags.TryGetValue("file", out fileConditionTuple) && fileConditionTuple.Item2 == pipeline);
            }

            return false;
        }

        /// <summary>
        /// Check if we should complete parameter names for switch cases on $PSBoundParameters.Keys
        /// </summary>
        private static List<CompletionResult> CompleteAgainstSwitchCaseCondition(CompletionContext completionContext)
        {
            var lastAst = completionContext.RelatedAsts.Last();

            PipelineAst conditionPipeline = null;
            Ast switchAst = null;

            // Check if we're in a switch statement (complete) or error statement (incomplete switch)
            var switchStatementAst = lastAst.Parent as SwitchStatementAst;
            if (switchStatementAst != null)
            {
                // Verify that the lastAst is one of the clause conditions (not in the body)
                bool isClauseCondition = switchStatementAst.Clauses.Any(clause => clause.Item1 == lastAst);

                if (!isClauseCondition)
                {
                    return null;
                }

                conditionPipeline = switchStatementAst.Condition as PipelineAst;
                switchAst = switchStatementAst;
            }
            else
            {
                // Check for incomplete switch parsed as ErrorStatementAst
                var errorStatementAst = lastAst.Parent as ErrorStatementAst;
                if (errorStatementAst == null || errorStatementAst.Kind == null ||
                    errorStatementAst.Kind.Kind != TokenKind.Switch)
                {
                    return null;
                }

                // For ErrorStatementAst, the case value is in Bodies, condition is in Conditions
                bool isInBodies = errorStatementAst.Bodies != null && errorStatementAst.Bodies.Any(body => body == lastAst);


Review comment (suggestion):
```suggestion
            if (lastAst.Parent is SwitchStatementAst switchStatementAst)
```

Code after:
                {
                    return false;
                }

                return (parentErrorStatement.Kind.Kind.Equals(TokenKind.Switch) &&
                        parentErrorStatement.Flags.TryGetValue("file", out fileConditionTuple) && fileConditionTuple.Item2 == pipeline);
            }

            return false;
        }

        /// <summary>
        /// Check if we should complete parameter names for switch cases on $PSBoundParameters.Keys
        /// </summary>
        private static List<CompletionResult> CompleteAgainstSwitchCaseCondition(CompletionContext completionContext)
        {
            var lastAst = completionContext.RelatedAsts.Last();

            PipelineAst conditionPipeline = null;
            Ast switchAst = null;

            // Check if we're in a switch statement (complete) or error statement (incomplete switch)
            if (lastAst.Parent is SwitchStatementAst switchStatementAst)
            {
                // Verify that the lastAst is one of the clause conditions (not in the body)
                bool isClauseCondition = switchStatementAst.Clauses.Any(clause => clause.Item1 == lastAst);

                if (!isClauseCondition)
                {
                    return null;
                }

                conditionPipeline = switchStatementAst.Condition as PipelineAst;
                switchAst = switchStatementAst;
            }
            else
            {
                // Check for incomplete switch parsed as ErrorStatementAst
                if (lastAst.Parent is not ErrorStatementAst errorStatementAst || errorStatementAst.Kind is null ||
                    errorStatementAst.Kind.Kind != TokenKind.Switch)
                {
                    return null;
                }

                // For ErrorStatementAst, the case value is in Bodies, condition is in Conditions
                bool isInBodies = errorStatementAst.Bodies != null && errorStatementAst.Bodies.Any(body => body == lastAst);

                if (!isInBodies)
                {
                    return null;
                }