Description
Prerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest released version
- Search the existing issues.
- Refer to the FAQ.
- Refer to Differences between Windows PowerShell 5.1 and PowerShell.
Steps to reproduce
Type in any of the following lines and add a linebreak after the equals sign:
using namespace whatever =
using module whatever =
using type whatever =
using command whatever =
As soon as you add the new line, PSReadline will display a parser error:
System.NullReferenceException: Object reference not set to an instance of an object.
at System.Management.Automation.Language.Parser.ExtentOf(Token first, Ast last)
at System.Management.Automation.Language.Parser.UsingStatementRule(Token usingToken)
at System.Management.Automation.Language.Parser.UsingStatementsRule()
The same thing happens in PowerShell 5.1
Expected behavior
No errors thrown.
Actual behavior
System.NullReferenceException: Object reference not set to an instance of an object.
at System.Management.Automation.Language.Parser.ExtentOf(Token first, Ast last)
at System.Management.Automation.Language.Parser.UsingStatementRule(Token usingToken)
at System.Management.Automation.Language.Parser.UsingStatementsRule()
### Error details
```console
PS C:\Users\Martin> get-error
Exception :
Type : System.Management.Automation.MethodInvocationException
ErrorRecord :
Exception :
Type : System.Management.Automation.ParentContainsErrorRecordException
Message : Exception calling "ReadLine" with "3" argument(s): "Unrecoverable error in PowerShell."
HResult : -2146233087
CategoryInfo : NotSpecified: (:) [], ParentContainsErrorRecordException
FullyQualifiedErrorId : ParseException
InvocationInfo :
ScriptLineNumber : 7
OffsetInLine : 5
HistoryId : -1
ScriptName : C:\Users\Martin\Documents\PowerShell\Modules\PSReadLine\2.2.0\PSReadLine.psm1
Line : [Microsoft.PowerShell.PSConsoleReadLine]::ReadLine($host.Runspace, $ExecutionContext, $lastRunStatus)
PositionMessage : At C:\Users\Martin\Documents\PowerShell\Modules\PSReadLine\2.2.0\PSReadLine.psm1:7 char:5
+ [Microsoft.PowerShell.PSConsoleReadLine]::ReadLine($host.Runspace …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PSScriptRoot : C:\Users\Martin\Documents\PowerShell\Modules\PSReadLine\2.2.0
PSCommandPath : C:\Users\Martin\Documents\PowerShell\Modules\PSReadLine\2.2.0\PSReadLine.psm1
CommandOrigin : Internal
ScriptStackTrace : at PSConsoleHostReadLine, C:\Users\Martin\Documents\PowerShell\Modules\PSReadLine\2.2.0\PSReadLine.psm1: line 7
TargetSite :
Name : ConvertToMethodInvocationException
DeclaringType : System.Management.Automation.ExceptionHandlingOps, System.Management.Automation, Version=7.2.0.10, Culture=neutral, PublicKeyToken=31bf3856ad364e35
MemberType : Method
Module : System.Management.Automation.dll
Message : Exception calling "ReadLine" with "3" argument(s): "Unrecoverable error in PowerShell."
Data : System.Collections.ListDictionaryInternal
InnerException :
Type : System.Management.Automation.ParseException
Message : Unrecoverable error in PowerShell.
ErrorRecord :
Exception :
Type : System.Management.Automation.ParentContainsErrorRecordException
Message : Unrecoverable error in PowerShell.
HResult : -2146233087
CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
FullyQualifiedErrorId : Parse
TargetSite :
Name : ParseInput
DeclaringType : System.Management.Automation.Language.Parser
MemberType : Method
Module : System.Management.Automation.dll
InnerException :
Type : System.NullReferenceException
TargetSite :
Name : ExtentOf
DeclaringType : System.Management.Automation.Language.Parser
MemberType : Method
Module : System.Management.Automation.dll
Message : Object reference not set to an instance of an object.
Source : System.Management.Automation
HResult : -2147467261
StackTrace :
at System.Management.Automation.Language.Parser.ExtentOf(Token first, Ast last)
at System.Management.Automation.Language.Parser.UsingStatementRule(Token usingToken)
at System.Management.Automation.Language.Parser.UsingStatementsRule()
at System.Management.Automation.Language.Parser.ScriptBlockRule(Token lCurly, Boolean isFilter, StatementAst predefinedStatementAst)
at System.Management.Automation.Language.Parser.ParseTask(String fileName, String input, List`1 tokenList, Boolean recursed, ParseMode parseMode)
at System.Management.Automation.Language.Parser.Parse(String fileName, String input, List`1 tokenList, ParseError[]& errors, ParseMode parseMode)
at System.Management.Automation.Language.Parser.ParseInput(String input, String fileName, Token[]& tokens, ParseError[]& errors)
Source : System.Management.Automation
HResult : -2146233087
StackTrace :
at System.Management.Automation.Language.Parser.ParseInput(String input, String fileName, Token[]& tokens, ParseError[]& errors)
at System.Management.Automation.Language.Parser.ParseInput(String input, Token[]& tokens, ParseError[]& errors)
at Microsoft.PowerShell.PSConsoleReadLine.ParseInput()
at Microsoft.PowerShell.PSConsoleReadLine.GenerateRender(String defaultColor)
at Microsoft.PowerShell.PSConsoleReadLine.ForceRender()
at Microsoft.PowerShell.PSConsoleReadLine.Render()
at Microsoft.PowerShell.PSConsoleReadLine.Insert(String s)
at Microsoft.PowerShell.PSConsoleReadLine.ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsics, CancellationToken cancellationToken, Nullable`1 lastRunStatus)
at Microsoft.PowerShell.PSConsoleReadLine.ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsics, Nullable`1 lastRunStatus)
at CallSite.Target(Closure , CallSite , Type , Object , Object , Object )
Source : System.Management.Automation
HResult : -2146233087
StackTrace :
at System.Management.Automation.ExceptionHandlingOps.ConvertToMethodInvocationException(Exception exception, Type typeToThrow, String methodName, Int32 numArgs, MemberInfo memberInfo)
at CallSite.Target(Closure , CallSite , Type , Object , Object , Object )
at System.Dynamic.UpdateDelegates.UpdateAndExecute4[T0,T1,T2,T3,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3)
at System.Management.Automation.Interpreter.DynamicInstruction`5.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
CategoryInfo : NotSpecified: (:) [], MethodInvocationException
FullyQualifiedErrorId : ParseException
InvocationInfo :
ScriptLineNumber : 7
OffsetInLine : 5
HistoryId : -1
ScriptName : C:\Users\Martin\Documents\PowerShell\Modules\PSReadLine\2.2.0\PSReadLine.psm1
Line : [Microsoft.PowerShell.PSConsoleReadLine]::ReadLine($host.Runspace, $ExecutionContext, $lastRunStatus)
PositionMessage : At C:\Users\Martin\Documents\PowerShell\Modules\PSReadLine\2.2.0\PSReadLine.psm1:7 char:5
+ [Microsoft.PowerShell.PSConsoleReadLine]::ReadLine($host.Runspace …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PSScriptRoot : C:\Users\Martin\Documents\PowerShell\Modules\PSReadLine\2.2.0
PSCommandPath : C:\Users\Martin\Documents\PowerShell\Modules\PSReadLine\2.2.0\PSReadLine.psm1
CommandOrigin : Internal
ScriptStackTrace : at PSConsoleHostReadLine, C:\Users\Martin\Documents\PowerShell\Modules\PSReadLine\2.2.0\PSReadLine.psm1: line 7
Environment data
PS C:\Users\Martin> $PSVersionTable
Name Value
---- -----
PSVersion 7.2.0-preview.10
PSEdition Core
GitCommitId 7.2.0-preview.10
OS Microsoft Windows 10.0.19044
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Visuals
No response