Open ghost opened 2 years ago
Debug show the trace throws on empty script block.
I can reproduced the problem on both 【ps 5.1】 and 【ps 6.2.7】
The Engine Working Group reviewed this issue and agree it's a bug that needs to be fixed.
I'm now encountering a case where custom classes with no explicit constructor trigger this issue as well. The classes are derived from a parent that also has no explicit constructor; I don't know if that's part of why. I am able to work around it by adding explicit 0-argument constructors with the body {return}
:
CustomBase {
[object] AbstractMethod() {
throw "Abstract method not implemented."
}
CustomBase() {return}
}
Custom : CustomBase {
[object] AbstractMethod() {
# Some implementation.
}
Custom() {return}
}
This seems to support that the issue has something to do with empty blocks; I assume the default implicit constructor is {}
.
@daxian-dbw I could refactor internal static string BriefMessage(IScriptPosition position)
method if you don't see more depth problem.
@iSazonov I haven't yet got a chance to understand the root cause. Will try taking a look next week.
Line 278 of Position.cs is the obvious starting point for the blame game, seeing as it's the only Insert()
call in BriefMessage()
. I assume that, for an empty block, the trace position is at column 0, so -1 is passed as the insert offset. Special-casing column 0 (and... negative columns??) is one fix, but maybe that should never happen; I'm obviously not familiar with how tracing is supposed to work internally. It also might be that position 0 is invalid in an empty string builder, in which case the line being empty needs handling or should be prevented from happening...
Amendment: Checked, position 0 is legal in empty string builders and does what you'd expect.
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.
Please reopen. Still an issue
Prerequisites
Steps to reproduce
Using PowerShell 7.2.1 (I ran on Windows Server 2019 and on Debian 11.2 (4.4 kernel in Windows Subsystem for Linux)), enable tracing at level 1 or 2 and run this script (note that removing the
Custom
class'sMethod
prevents the issue from occurring, but switching toNew-Object
does not):Expected behavior
Actual behavior
Error details
Environment data
OR
Visuals
No response