diff --git a/src/Compiler/src/Compiler/XSharpCodeAnalysis/Parser/XSharpTreeTransformationCore.cs b/src/Compiler/src/Compiler/XSharpCodeAnalysis/Parser/XSharpTreeTransformationCore.cs index f2c7bbbe8b..25a36b1843 100644 --- a/src/Compiler/src/Compiler/XSharpCodeAnalysis/Parser/XSharpTreeTransformationCore.cs +++ b/src/Compiler/src/Compiler/XSharpCodeAnalysis/Parser/XSharpTreeTransformationCore.cs @@ -8846,6 +8846,8 @@ public override void ExitArgListExpression([NotNull] XP.ArgListExpressionContext #endregion #region Arguments + // _emptyArgs and _emptyBracketedArgs are shared by all compilations of the process: never Put() them on a context or + // change them otherwise (see ExitArgumentList). private static ArgumentListSyntax _emptyArgs = null; protected ArgumentListSyntax EmptyArgumentList() { @@ -8938,12 +8940,17 @@ public override void ExitArgumentList([NotNull] XP.ArgumentListContext context) // argumentList : Args+=namedArgument (COMMA Args+=namedArgument)* // ; // namedArgument may match an empty argument. - var args = _pool.AllocateSeparated(); if (context.IsMissing) { - context.Put(EmptyArgumentList()); + // A node of its own for every call: Put() stores this context as the node's XNode, and the source location + // of the list ('(' is where Roslyn takes [CallerLineNumber] from) is mapped through that XNode. The shared + // EmptyArgumentList(), and any list from the syntax factory, whose node cache returns one node for the same + // singleton tokens, gave every call without arguments the line of the last such call transformed. + // Created directly to bypass the cache; the singleton tokens keep the positions of the other lists. + context.Put(new ArgumentListSyntax(SyntaxKind.ArgumentList, SyntaxFactory.OpenParenToken, null, SyntaxFactory.CloseParenToken)); return; } + var args = _pool.AllocateSeparated(); var openParen = SyntaxFactory.OpenParenToken; var closeParen = SyntaxFactory.CloseParenToken; foreach (var argCtx in context._Args) diff --git a/src/CompilerTests/Applications/C992/Prg/C992.prg b/src/CompilerTests/Applications/C992/Prg/C992.prg new file mode 100644 index 0000000000..6dbda0ffb3 --- /dev/null +++ b/src/CompilerTests/Applications/C992/Prg/C992.prg @@ -0,0 +1,62 @@ +// 992. [CallerLineNumber] for a call without arguments +// Every call without arguments got the line of the last call without arguments in the compilation +// (in a compiler server build even of another project): all of them shared one empty argument list. +USING System.Runtime.CompilerServices + +GLOBAL gnLine AS INT + +FUNCTION LineOf(n := 0 AS INT, [CallerLineNumber] nLine := 0 AS INT) AS INT +RETURN nLine + +FUNCTION FileOf([CallerFilePath] cFile := "" AS STRING) AS STRING +RETURN cFile + +PROCEDURE SetLine([CallerLineNumber] nLine := 0 AS INT) + gnLine := nLine +RETURN + +CLASS Caller + METHOD LineOf([CallerMemberName] cMember := "" AS STRING, [CallerLineNumber] nLine := 0 AS INT) AS INT + xAssert(cMember == "Typed" .or. cMember == "Untyped") + RETURN nLine + + METHOD Typed() AS VOID + xAssert(SELF:LineOf() == 24) + xAssert(SELF:LineOf() == 25) + + METHOD Untyped(a, b) AS VOID CLIPPER + IF a == 1 + xAssert(SELF:LineOf() == 29) + ENDIF +END CLASS + +CLASS Base + PROPERTY Line AS INT AUTO + CONSTRUCTOR([CallerLineNumber] nLine := 0 AS INT) + SELF:Line := nLine +END CLASS + +CLASS Derived INHERIT Base + CONSTRUCTOR() + SUPER() +END CLASS + +FUNCTION Start() AS VOID + xAssert(LineOf() == 45) + xAssert(LineOf(1) == 46) + xAssert(LineOf() == 47) + Caller{}:Typed() + Caller{}:Untyped(1, 2) + xAssert(Derived{}:Line == 41) + DO SetLine + xAssert(gnLine == 51) + xAssert(FileOf():EndsWith("C992.prg", StringComparison.OrdinalIgnoreCase)) + xAssert(LineOf() == 54) +RETURN + +PROC xAssert(l AS LOGIC) +IF .NOT. l + THROW Exception{"Incorrect result in line " + System.Diagnostics.StackTrace{TRUE}:GetFrame(1):GetFileLineNumber():ToString()} +ENDIF +? "Assertion passed" +RETURN diff --git a/src/CompilerTests/Applications/RuntimeTests/Prg/RuntimeTests.prg b/src/CompilerTests/Applications/RuntimeTests/Prg/RuntimeTests.prg index 2a98073f34..0cad2786c2 100644 --- a/src/CompilerTests/Applications/RuntimeTests/Prg/RuntimeTests.prg +++ b/src/CompilerTests/Applications/RuntimeTests/Prg/RuntimeTests.prg @@ -35,7 +35,7 @@ FUNCTION Start() AS INT "C905", "C908", "C913", "C914", "C915", "C921", "C926", "C932", "C936", "C937", "C938", "C939", ; "C941", "C942", "C943", /*"C946",*/ "C948", "C950", "C951", "C952", "C953", "C955", ; "C958", "C960", "C961", "C962", "C963", "C964", "C965", "C969", "C970", "C973", "C976", "C977", ; - "C978", "C979", "C980", "C981", "C982", "C984", "C987", "C988", ; + "C978", "C979", "C980", "C981", "C982", "C984", "C987", "C988", "C992", ; ; "D000", "D002", ; ; diff --git a/src/CompilerTests/xSharp Tests30.viproj b/src/CompilerTests/xSharp Tests30.viproj index 93c1cb3382..376052e7d8 100644 --- a/src/CompilerTests/xSharp Tests30.viproj +++ b/src/CompilerTests/xSharp Tests30.viproj @@ -150531,6 +150531,129 @@ AppConfig = Release,22222222-2222-2222-2222-222222222222 ForceX86=0 Optimize=0 ENDApplication = C991 - Problems with the /fox3 option - using colon for members access #2141 + +ApplicationGroup = 61836030-A334-4343-8288-FCFDE6361FD6 +; ************** APPLICATION C992 - CallerLineNumber for a call without arguments ************* +Application = C992 - CallerLineNumber for a call without arguments +IDEVersion = 1.06 +GalleryName = +GalleryPage = +GalleryDefaultName = +Target = 0 +Platform = x86 +Language = XSharp +Runtime = CLR4 +NetVersion = +Dialect = VO +Folder = %ProjectPath%\Applications\C992\ +PrgSubFolder = \Prg +ResourcesSubFolder = +Description = +NameSpace = +Assembly = C992 +Extension = +ApplicationIcon = +OutputFolder = +Frameworks = 1 +GUID = 282A49A1-3D1D-4F99-B6F8-9041C2B5B486 +IncludeInProjectBuild = 1 +IncludeInProjectSearch = 1 +IncludeInProjectExport = 1 +EmitAssemblyProperties = 0 +EmitNetVersion = 0 +IncludePath = +StdDefsFile = +AppToRun = +SignAssembly = 0 +KeyFile = + +[ExportOptions] +ExportResources = 0 +ExportImages = 0 +[C992 - CallerLineNumber for a call without arguments FileGroups] +[C992 - CallerLineNumber for a call without arguments Files] +File = %AppPath%\Prg\C992.prg +FileGUID = 9F670233-75E8-4E7A-9B10-D5CA7FCAB71F +FileType = Code +CopyToBin = 0 +[C992 - CallerLineNumber for a call without arguments References] +ReferenceGAC = CLR4,XSharp.Core,1,0,3.0.0.0 +ReferenceGAC = CLR4,XSharp.RT,1,0,3.0.0.0 +[C992 - CallerLineNumber for a call without arguments Resources] +[C992 - CallerLineNumber for a call without arguments Native Resources] +[C992 - CallerLineNumber for a call without arguments License files] +[C992 - CallerLineNumber for a call without arguments General Options] +Switches= +IgnoreWarnings= +ZeroArrays=0 +CaseSensitive=0 +ImplicitNamespace=0 +VO1=0 +VO2=0 +VO3=0 +VO4=0 +VO5=0 +VO6=0 +VO7=0 +VO8=0 +VO9=0 +VO10=0 +VO11=0 +VO12=0 +VO13=0 +VO14=0 +VO15=0 +VO16=0 +VO17=0 +FOX1=0 +FOX2=0 +XPP1=0 +LateBound=0 +Unsafe=0 +Undeclared=0 +EnforceSelf=0 +EnforceOverride=0 +UseNativeVersion=0 +MemVar=0 +IgnoreStdDefs=0 +Ovf=0 +FOvf=0 +ModernSyntax=0 +NamedArgs=0 +InitLocals=0 +AllowOldStyleAssignments=0 +AllowDotOption=0 +ResponseOnly=0 +[C992 - CallerLineNumber for a call without arguments Configurations] +AppConfig = Debug,11111111-1111-1111-1111-111111111111 + Switches= + SwitchesCF= + CommandLine= + CommandLineCF= + Debug=1 + DebugInit=1 + DefineDebug=1 + DefineTrace=0 + SyntaxOnly=0 + WarningsErrors=0 + ForceConsole=0 + ForceX86=0 + Optimize=0 +AppConfig = Release,22222222-2222-2222-2222-222222222222 + Switches= + SwitchesCF= + CommandLine= + CommandLineCF= + Debug=0 + DebugInit=0 + DefineDebug=0 + DefineTrace=0 + SyntaxOnly=0 + WarningsErrors=0 + ForceConsole=0 + ForceX86=0 + Optimize=0 +ENDApplication = C992 - CallerLineNumber for a call without arguments [EndApplications] [Configurations]