Skip to content

Conversation

@jjonescz
Copy link
Member

Fixes #52108.

@jjonescz jjonescz requested a review from Copilot December 10, 2025 14:19
@jjonescz jjonescz added the Area-run-file Items related to the "dotnet run <file>" effort label Dec 10, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a bug where file-like arguments were incorrectly discarded when the same filename appeared both as the entry point and as a program argument (e.g., dotnet Program.cs Program.cs). The fix changes the token filtering logic from value-based comparison to reference-based comparison, ensuring only the first occurrence (the entry point) is removed while preserving subsequent occurrences as arguments.

Key changes:

  • Modified TryRunFileBasedApp to capture the actual token object rather than just its value
  • Changed token filtering to use reference equality instead of value equality
  • Added a test case specifically for the bug scenario (dotnet Program.cs Program.cs)

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/Cli/dotnet/Program.cs Fixed token filtering logic in TryRunFileBasedApp to use reference equality, preventing all file-like arguments from being discarded when they match the entry point filename
test/dotnet.Tests/CommandTests/Run/RunFileTests.cs Added test case verifying that dotnet Program.cs Program.cs correctly passes "Program.cs" as an argument to the executed program

foreach (var token in parseResult.Tokens)
{
if (token.Type != TokenType.Argument || token.Value != unmatchedCommandOrFile)
if (token != unmatchedCommandOrFile)
Copy link
Member

@RikkiGibson RikkiGibson Dec 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There isn't a need to make a further change, but, I was wondering if otherTokens ends up being equivalent to parseResult.Tokens[1..]? (I guess with some intermediate .Value access inserted.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that's guaranteed, there might be some special tokens before the subcommand argument. But I'm also not sure it makes sense to try to preserve the order until we have a motivating scenario.

@jjonescz
Copy link
Member Author

/ba-g known failures

@jjonescz jjonescz merged commit 283babf into dotnet:release/10.0.2xx Dec 11, 2025
29 of 34 checks passed
@jjonescz jjonescz deleted the sprint-norun-args branch December 11, 2025 10:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-run-file Items related to the "dotnet run <file>" effort

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants