Skip to content

Conversation

@jjonescz
Copy link
Member

Fixes #7091.

@jjonescz jjonescz force-pushed the 7091-System-in-namespace branch from dbd745a to 487d77a Compare February 23, 2023 10:44
@jjonescz jjonescz force-pushed the 7091-System-in-namespace branch from 487d77a to 7dc27bf Compare February 23, 2023 12:02
@jjonescz jjonescz marked this pull request as ready for review February 23, 2023 12:51
@jjonescz jjonescz requested review from a team as code owners February 23, 2023 12:51
Comment on lines -57 to -60
context.CodeWriter
.Write("((")
.Write(typeof(Action).FullName)
.Write(")(");
Copy link
Contributor

Choose a reason for hiding this comment

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

💭 I think I might prefer the form on the left, and just change (( to ((global::

((global::System.Action)(() => {
#nullable restore
#line 1 "x:\dir\subdir\Test\TestComponent.cshtml"
global::System.Object __typeHelper = nameof(X.System.Y);
Copy link
Contributor

Choose a reason for hiding this comment

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

📝 I'm expecting this to be just object by the end of this change

Copy link
Member Author

@jjonescz jjonescz Feb 23, 2023

Choose a reason for hiding this comment

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

I don't plan to update everything to object (that's orthogonal to the issue), I just fixed cases where there was System.Object without global::, failing the new test cases. I could perhaps use global::System.Object everywhere but object seemed better.

Copy link
Contributor

Choose a reason for hiding this comment

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

object is definitely better.


codeDocument.SetDocumentIntermediateNode(document);

static bool TryRemoveGlobalPrefixFromDefaultUsing(in UsingReference usingReference, out UsingReference trimmed)
Copy link
Contributor

Choose a reason for hiding this comment

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

📝 It's difficult to review the impact of this change in isolation because baselines weren't updated with each change

Copy link
Member Author

@jjonescz jjonescz Feb 23, 2023

Choose a reason for hiding this comment

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

That's because this change caused failures - there was a new warning about duplicate usings in the new tests. I don't think anything changed in the old tests. But I could verify that.

[InlineData("Project.Foo", "global::Project.Bar", false)]
[InlineData("Project.Bar.Foo", "Project", false)]
[InlineData("Bar.Foo", "Project", false)]
public void IsTypeInNamespace_WorksAsExpected(string typeName, string @namespace, bool expected)
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 expected shouldn't be a parameter here. It should be a variable inside the test which is initialized with a switch expression, e.g.:

var expected = (typeName, @namespace) switch
{
  ("", "") => true,
  ("Foo", "Project") => true,
  ("Project.Foo", "Project") => true,
  ("Project.Foo", "global::Project") => true,
  _ => false,
};

Copy link
Member Author

Choose a reason for hiding this comment

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

Why would that be better? It would need duplicating the test data.

Copy link
Contributor

@sharwell sharwell Feb 23, 2023

Choose a reason for hiding this comment

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

Why would that be better?

The parameters to a test are part of the test identity. When expected outcomes are part of the parameter list, it is impossible to update code in a manner that changes the expected outcome of a test without deleting the entire test history. This improves both CI behavior and local iterations as the test is initially developed.

It would need duplicating the test data.

Yes, and for this type of situation it's completely acceptable. Duplication is not as much a maintenance problem when coupled (both copies are highly likely to appear on the same screen at the same time).

Copy link
Member Author

Choose a reason for hiding this comment

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

That's interesting. I wouldn't think expected outcomes of unit tests change, that's what snapshot tests are for. Although I guess the line between the two is not that clear.

Copy link
Contributor

@sharwell sharwell left a comment

Choose a reason for hiding this comment

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

Reviewing the changes to baselines, I want to see this broken into three prerequisites, each as their own PR:

  1. af335c3, plus baseline update
  2. The part of 4f09abc that changes System.Object to object, plus baseline update
  3. The part of 4f09abc that changes System.Action to global::System.Action, plus baseline update

@jjonescz
Copy link
Member Author

Alright, I can split this into multiple PRs. Marking as draft for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-compiler Umbrella for all compiler issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Code generators having issues with projects with System in namespace

3 participants