Skip to content

StackOverflowException when PSReadLine is imported inside another imported module #24904

@DaRacci

Description

@DaRacci

Prerequisites

  • Write a descriptive title.
  • Make sure you are able to repro it on the latest released version
  • Search the existing issues, especially the pinned issues.

Exception report

Repeated 69441 times:
--------------------------------
   at System.Management.Automation.PSModuleInfo.GetExportedTypeDefinitions()
--------------------------------
   at System.Management.Automation.Language.Compiler.LoadUsingsImpl(System.Collections.Generic.IEnumerable`1<System.Management.Automation.Language.UsingStatementAst>, System.Reflection.Assembly[] ByRef)
   at System.Management.Automation.Language.Compiler.GenerateLoadUsings(System.Collections.Generic.IEnumerable`1<System.Management.Automation.Language.UsingStatementAst>, Boolean, System.Collections.Generic.List`1<System.Linq.Expressions.Expression>)
   at System.Management.Automation.Language.Compiler.GenerateTypesAndUsings(System.Management.Automation.Language.ScriptBlockAst, System.Collections.Generic.List`1<System.Linq.Expressions.Expression>)
   at System.Management.Automation.Language.Compiler.CompileSingleLambda(System.Collections.ObjectModel.ReadOnlyCollection`1<System.Management.Automation.Language.StatementAst>, System.Collections.ObjectModel.ReadOnlyCollection`1<System.Management.Automation.Language.TrapStatementAst>, System.String, System.Management.Automation.Language.IScriptExtent, System.Management.Automation.Language.IScriptExtent, System.Management.Automation.Language.ScriptBlockAst)
   at System.Management.Automation.Language.Compiler.CompileNamedBlock(System.Management.Automation.Language.NamedBlockAst, System.String, System.Management.Automation.Language.ScriptBlockAst)
   at System.Management.Automation.Language.Compiler.VisitScriptBlock(System.Management.Automation.Language.ScriptBlockAst)
   at System.Management.Automation.Language.Compiler.Compile(System.Management.Automation.CompiledScriptBlockData, Boolean)
   at System.Management.Automation.CompiledScriptBlockData.ReallyCompile(Boolean)
   at System.Management.Automation.CompiledScriptBlockData.CompileOptimized()
   at System.Management.Automation.CompiledScriptBlockData.Compile(Boolean)
   at System.Management.Automation.PSScriptCmdlet..ctor(System.Management.Automation.ScriptBlock, Boolean, Boolean, System.Management.Automation.ExecutionContext)
   at System.Management.Automation.CommandProcessor.Init(System.Management.Automation.IScriptCommandInfo)
   at System.Management.Automation.CommandDiscovery.GetScriptAsCmdletProcessor(System.Management.Automation.IScriptCommandInfo, System.Management.Automation.ExecutionContext, Boolean, Boolean, System.Management.Automation.SessionStateInternal)
   at System.Management.Automation.CommandDiscovery.CreateCommandProcessorForScript(System.Management.Automation.ExternalScriptInfo, System.Management.Automation.ExecutionContext, Boolean, System.Management.Automation.SessionStateInternal)
   at System.Management.Automation.CommandDiscovery.LookupCommandProcessor(System.Management.Automation.CommandInfo, System.Management.Automation.CommandOrigin, System.Nullable`1<Boolean>, System.Management.Automation.SessionStateInternal)
   at System.Management.Automation.CommandDiscovery.LookupCommandProcessor(System.String, System.Management.Automation.CommandOrigin, System.Nullable`1<Boolean>)
   at System.Management.Automation.ExecutionContext.CreateCommand(System.String, Boolean)
   at System.Management.Automation.Language.PseudoParameterBinder.PrepareCommandElements(System.Management.Automation.ExecutionContext, System.Management.Automation.Language.CommandParameterAst)
   at System.Management.Automation.Language.PseudoParameterBinder.DoPseudoParameterBinding(System.Management.Automation.Language.CommandAst, System.Type, System.Management.Automation.Language.CommandParameterAst, BindingType, Boolean)
   at System.Management.Automation.CompletionCompleters.CompleteCommandParameter(System.Management.Automation.CompletionContext)
   at System.Management.Automation.CompletionAnalysis.GetResultForIdentifier(System.Management.Automation.CompletionContext, Int32 ByRef, Int32 ByRef)
   at System.Management.Automation.CompletionAnalysis.GetResultHelper(System.Management.Automation.CompletionContext, Int32 ByRef, Int32 ByRef)
   at System.Management.Automation.CompletionAnalysis.GetResults(System.Management.Automation.PowerShell, Int32 ByRef, Int32 ByRef)
   at System.Management.Automation.CommandCompletion.CompleteInputImpl(System.Management.Automation.Language.Ast, System.Management.Automation.Language.Token[], System.Management.Automation.Language.IScriptPosition, System.Collections.Hashtable)
   at DynamicClass.CallSite.Target(System.Runtime.CompilerServices.Closure, System.Runtime.CompilerServices.CallSite, System.Type, System.String, Int32, System.Collections.Hashtable)
   at System.Management.Automation.Interpreter.DynamicInstruction`5[[System.__Canon, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Int32, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Run(System.Management.Automation.Interpreter.InterpretedFrame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(System.Management.Automation.Interpreter.InterpretedFrame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(System.Management.Automation.Interpreter.InterpretedFrame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(System.Management.Automation.Interpreter.InterpretedFrame)
   at System.Management.Automation.Interpreter.Interpreter.Run(System.Management.Automation.Interpreter.InterpretedFrame)
   at System.Management.Automation.Interpreter.LightLambda.RunVoid1[[System.__Canon, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](System.__Canon)
   at System.Management.Automation.PSScriptCmdlet.RunClause(System.Action`1<System.Management.Automation.Language.FunctionContext>, System.Object, System.Object)
   at System.Management.Automation.CommandProcessorBase.Complete()
   at System.Management.Automation.CommandProcessorBase.DoComplete()
   at System.Management.Automation.Internal.PipelineProcessor.DoCompleteCore(System.Management.Automation.CommandProcessorBase)
   at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(System.Object)
   at System.Management.Automation.Runspaces.LocalPipeline.InvokeHelper()
   at System.Management.Automation.Runspaces.LocalPipeline.InvokeThreadProc()
   at System.Management.Automation.Runspaces.LocalPipeline.StartPipelineExecution()
   at System.Management.Automation.Runspaces.PipelineBase.CoreInvoke(System.Collections.IEnumerable, Boolean)
   at System.Management.Automation.Runspaces.PipelineBase.Invoke(System.Collections.IEnumerable)
   at System.Management.Automation.PowerShell+Worker.ConstructPipelineAndDoWork(System.Management.Automation.Runspaces.Runspace, Boolean)
   at System.Management.Automation.PowerShell.CoreInvokeHelper[[System.__Canon, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](System.Management.Automation.PSDataCollection`1<System.__Canon>, System.Management.Automation.PSDataCollection`1<System.__Canon>, System.Management.Automation.PSInvocationSettings)
   at System.Management.Automation.PowerShell.CoreInvoke[[System.__Canon, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](System.Management.Automation.PSDataCollection`1<System.__Canon>, System.Management.Automation.PSDataCollection`1<System.__Canon>, System.Management.Automation.PSInvocationSettings)
   at System.Management.Automation.PowerShell.Invoke(System.Collections.IEnumerable, System.Management.Automation.PSInvocationSettings)
   at System.Management.Automation.CommandCompletion.CallScriptWithStringParameterSet(System.String, Int32, System.Collections.Hashtable, System.Management.Automation.PowerShell)
   at System.Management.Automation.CommandCompletion.CompleteInput(System.String, Int32, System.Collections.Hashtable, System.Management.Automation.PowerShell)
   at Microsoft.PowerShell.PSConsoleReadLine+<>c__DisplayClass33_0.<Microsoft.PowerShell.Internal.IPSConsoleReadLineMockableMethods.CompleteInput>b__0()
   at PlatformWindows.CallPossibleExternalApplication[[System.__Canon, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](System.Func`1<System.__Canon>)
   at Microsoft.PowerShell.PSConsoleReadLine.CallPossibleExternalApplication[[System.__Canon, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](System.Func`1<System.__Canon>)
   at Microsoft.PowerShell.PSConsoleReadLine.Microsoft.PowerShell.Internal.IPSConsoleReadLineMockableMethods.CompleteInput(System.String, Int32, System.Collections.Hashtable, System.Management.Automation.PowerShell)
   at Microsoft.PowerShell.PSConsoleReadLine.GetCompletions()
   at Microsoft.PowerShell.PSConsoleReadLine.Complete(Boolean)
   at Microsoft.PowerShell.PSConsoleReadLine.TabCompleteNext(System.Nullable`1<System.ConsoleKeyInfo>, System.Object)
   at Microsoft.PowerShell.PSConsoleReadLine.ProcessOneKey(Microsoft.PowerShell.PSKeyInfo, System.Collections.Generic.Dictionary`2<Microsoft.PowerShell.PSKeyInfo,KeyHandler>, Boolean, System.Object)
   at Microsoft.PowerShell.PSConsoleReadLine.InputLoop()
   at Microsoft.PowerShell.PSConsoleReadLine.ReadLine(System.Management.Automation.Runspaces.Runspace, System.Management.Automation.EngineIntrinsics, System.Threading.CancellationToken, System.Nullable`1<Boolean>)
   at DynamicClass.CallSite.Target(System.Runtime.CompilerServices.Closure, System.Runtime.CompilerServices.CallSite, System.Type, System.Object, System.Object, System.Object)
   at System.Management.Automation.Interpreter.DynamicInstruction`5[[System.__Canon, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Run(System.Management.Automation.Interpreter.InterpretedFrame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(System.Management.Automation.Interpreter.InterpretedFrame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(System.Management.Automation.Interpreter.InterpretedFrame)
   at System.Management.Automation.Interpreter.Interpreter.Run(System.Management.Automation.Interpreter.InterpretedFrame)
   at System.Management.Automation.Interpreter.LightLambda.RunVoid1[[System.__Canon, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](System.__Canon)
   at System.Management.Automation.DlrScriptCommandProcessor.RunClause(System.Action`1<System.Management.Automation.Language.FunctionContext>, System.Object, System.Object)
   at System.Management.Automation.DlrScriptCommandProcessor.Complete()
   at System.Management.Automation.CommandProcessorBase.DoComplete()
   at System.Management.Automation.Internal.PipelineProcessor.DoCompleteCore(System.Management.Automation.CommandProcessorBase)
   at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(System.Object)
   at System.Management.Automation.Runspaces.LocalPipeline.InvokeHelper()
   at System.Management.Automation.Runspaces.LocalPipeline.InvokeThreadProc()
   at System.Management.Automation.Runspaces.PipelineThread.WorkerProc()
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)

Screenshot

Image

Environment data

PS Version: 7.5.0
PS HostName: ConsoleHost (Windows Terminal)
PSReadLine Version: 2.3.6
PSReadLine EditMode: Windows
OS: 10.0.26100.1 (WinBuild.160101.0800)
BufferWidth: 210
BufferHeight: 50

Steps to reproduce

  • Create a psm1 module which through either Import-Module or Using module imports PSReadLine
  • Create a ps1 script with a param block
  • Import the psm1 module from the ps1 script
  • Try to tab complete an argument from the ps1 script

test.psm1

using module @{
    ModuleName = "PSReadLine";
    ModuleVersion = "2.3.6";
}

test.ps1

using module .\test.psm1

param()

Expected behavior

That there is no StackOverflowException and tab completion works.

Actual behavior

StackOverflowException and crash of the powershell session.

Metadata

Metadata

Assignees

No one assigned

    Labels

    In-PRIndicates that a PR is out for the issueIssue-BugIssue has been identified as a bug in the product

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions