Reproducible on 6.1.0 and on master b525b1f
Steps to reproduce
$sb = {
<#
.SYNOPSIS
Sample synopsis.
#>
process { }
}
$str = [String]$sb
Set-Item -Path function:private:FunctionFromString -Value $str
(Get-Help FunctionFromString).Synopsis
Set-Item -Path function:private:FunctionFromScriptBlock -Value $sb
(Get-Help FunctionFromScriptBlock).Synopsis
Expected behavior
Sample synopsis.
Sample synopsis.
Actual behavior
Sample synopsis.
FunctionFromScriptBlock
Environment data
> $PSVersionTable
Name Value
---- -----
PSVersion 6.1.0
PSEdition Core
GitCommitId 6.1.0
OS Microsoft Windows 10.0.17134
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Analysis
The difference between these two cases can be observed in the following block of code:
|
else if (ast == rootAst) |
|
{ |
|
startTokenIndex = savedStartIndex = 0; |
|
lastTokenIndex = tokens.Length - 1; |
|
} |
|
else |
|
{ |
|
// This case should be rare (but common with implicit remoting). |
|
// We have a script block that was used to generate a function like: |
|
// $sb = { } |
|
// set-item function:foo $sb |
|
// help foo |
|
startTokenIndex = savedStartIndex = FirstTokenInExtent(tokens, ast.Extent) - 1; |
|
lastTokenIndex = LastTokenInExtent(tokens, ast.Extent, startTokenIndex); |
|
|
|
Diagnostics.Assert(tokens[startTokenIndex + 1].Kind == TokenKind.LCurly, |
|
"Unexpected first token in script block"); |
|
Diagnostics.Assert(tokens[lastTokenIndex].Kind == TokenKind.RCurly, |
|
"Unexpected last token in script block"); |
|
} |
[ScriptBlock] cases are handled by the else statement where the startTokenIndex is being set to the position before script block itself. Changing - 1 to + 1 in the line
|
startTokenIndex = savedStartIndex = FirstTokenInExtent(tokens, ast.Extent) - 1; |
solves the problem.
May I prepare a PR for this?
Reproducible on 6.1.0 and on master b525b1f
Steps to reproduce
Expected behavior
Actual behavior
Environment data
Analysis
The difference between these two cases can be observed in the following block of code:
PowerShell/src/System.Management.Automation/help/HelpCommentsParser.cs
Lines 1145 to 1164 in b525b1f
[ScriptBlock]cases are handled by theelsestatement where thestartTokenIndexis being set to the position before script block itself. Changing- 1to+ 1in the linePowerShell/src/System.Management.Automation/help/HelpCommentsParser.cs
Line 1157 in b525b1f
solves the problem.
May I prepare a PR for this?