Skip to content

Wrong [CallerLineNumber] for calls without arguments - #2194

Merged
RobertvanderHulst merged 1 commit into
X-Sharp:devfrom
hpetriffer:hpetriffer/callerline-empty-args
Nov 23, 2026
Merged

RobertvanderHulst merged 1 commit into
X-Sharp:devfrom
hpetriffer:hpetriffer/callerline-empty-args

Conversation

@hpetriffer

Copy link
Copy Markdown
Contributor

Summary

A call without arguments to a method or function with a [CallerLineNumber] parameter got the line of the last call
without arguments in the compilation instead of its own line. In builds through the compiler server (/shared) the value
could even come from another project. Calls with arguments were correct. X# 3.1 shows the same behaviour.

FUNCTION Log(a := 0 AS INT, [System.Runtime.CompilerServices.CallerLineNumber] nLine := 0 AS INT) AS VOID
    System.Console.WriteLine(a:ToString() + " " + nLine:ToString())

FUNCTION Start() AS VOID
    Log()      // line 5: reported 7
    Log(1)     // line 6: 6
    Log()      // line 7: 7

Cause: for an empty argument list ExitArgumentList attached the parse context to the shared EmptyArgumentList() node
(Put() sets its XNode). Roslyn takes the caller line from the location of the argument list, which X# maps through
that XNode, so every call without arguments reported the position of the last one transformed. Creating the list through
the syntax factory does not help: its node cache returns the same node for the same singleton tokens.

 ExitArgumentList(context)
   if context.IsMissing
-    context.Put(EmptyArgumentList())          // one node for all calls in the process
+    context.Put(new ArgumentListSyntax(        // one node per call, not from the node cache
+        ArgumentList, OpenParenToken, null, CloseParenToken))
     return

The usual singleton tokens are kept, so diagnostic locations do not change.

Evidence

  • Before: the example above (/dialect:Core) prints 0 7 | 1 6 | 0 7; new test C992 fails
    (Incorrect result in line 45).
    After: 0 5 | 1 6 | 0 7; C992 passes.
  • C992 (runtime test) checks the line of calls without arguments from a function, a typed method, a CLIPPER method,
    a SUPER() constructor chain and DO without WITH, plus [CallerFilePath] and calls with arguments.
  • Compiler test suite with and without the fix: the only difference is C992.
  • Diagnostic locations: XS0029/XS7036/XS0219 on expressions that end in an empty call report the same line and column as
    before.

Merge Danger

Door: two-way

Blast Radius: narrow

Only argument lists of calls written without arguments get their own syntax node; what changes for users is the
[CallerLineNumber] value of such calls. The shared EmptyArgumentList() used for compiler-generated calls is not
touched.

🤖 Generated with Claude Code

A call without arguments, e.g. Log(), got the line number of the last call without arguments in the compilation instead
of its own line; in builds through the compiler server the value could even come from another project. Calls with
arguments were correct.

For an empty argument list ExitArgumentList attached the parse context to the shared EmptyArgumentList() node (Put()
sets its XNode). Roslyn takes the caller line from the location of the argument list, which X# maps through that XNode,
so every call without arguments reported the position of the last one transformed. Creating the list through the syntax
factory would not help: its node cache returns the same node for the same singleton tokens.

ExitArgumentList now creates a separate ArgumentListSyntax for every empty argument list (with the constructor, which
bypasses the node cache) and keeps the usual tokens, so diagnostic locations do not change.

Test C992: functions, typed and CLIPPER methods, a SUPER() constructor chain, DO without WITH, [CallerFilePath], and
calls with arguments.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@audit-bench-ai

Copy link
Copy Markdown

Audit Bench Ai skipped the automatic review of this commit: The Free plan can scan 1 repository. Upgrade to Pro to scan more.

@RobertvanderHulst
RobertvanderHulst merged commit 734a9e8 into X-Sharp:dev Nov 23, 2026
2 checks passed
@hpetriffer
hpetriffer deleted the hpetriffer/callerline-empty-args branch November 24, 2026 07:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants