diff --git a/src/System.Management.Automation/engine/Modules/ScriptAnalysis.cs b/src/System.Management.Automation/engine/Modules/ScriptAnalysis.cs index 3c62e4cb3..49351032f 100644 --- a/src/System.Management.Automation/engine/Modules/ScriptAnalysis.cs +++ b/src/System.Management.Automation/engine/Modules/ScriptAnalysis.cs @@ -473,7 +473,7 @@ namespace System.Management.Automation var argumentAst = specifiedParameter.Argument; if (argumentAst == null) { - argumentAst = commandAst.CommandElements[i + 1] as ExpressionAst; + argumentAst = commandAst.CommandElements[i] as ExpressionAst; if (argumentAst != null) { i += 1; diff --git a/test/powershell/Host/TabCompletion/BugFix.Tests.ps1 b/test/powershell/Host/TabCompletion/BugFix.Tests.ps1 index 0769281ee..38feaceb4 100644 --- a/test/powershell/Host/TabCompletion/BugFix.Tests.ps1 +++ b/test/powershell/Host/TabCompletion/BugFix.Tests.ps1 @@ -27,4 +27,12 @@ Describe "Tab completion bug fix" -Tags "CI" { $result.CompletionMatches.Count | Should Be 1 $result.CompletionMatches[0].CompletionText | Should Be "pscustomobject" } + It "Issue#1345 - 'Import-Module -n' should work" { + $cmd = "Import-Module -n" + $result = TabExpansion2 -inputScript $cmd -cursorColumn $cmd.Length + $result.CompletionMatches.Count | Should Be 3 + $result.CompletionMatches[0].CompletionText | Should Be "-Name" + $result.CompletionMatches[1].CompletionText | Should Be "-NoClobber" + $result.CompletionMatches[2].CompletionText | Should Be "-NoOverwrite" + } }