-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
File types binding #60977
File types binding #60977
Conversation
src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberMethodSymbol.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Symbols/Source/SourceNamespaceSymbol.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Declarations/SingleTypeDeclaration.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Test/Symbol/Symbols/Source/FileModifierTests.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Test/Symbol/Symbols/Source/FileModifierTests.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberMethodSymbol.cs
Show resolved
Hide resolved
} | ||
|
||
// PROTOTYPE(ft): | ||
// ensure nested types within 'file' types are either disallowed or treated as implicitly 'file' | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should test accessibility restrictions on record positional members as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some more test ideas:
- Do we have tests with aliases of file-types or including file-types?
- File-type containing extension methods
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should test accessibility restrictions on record positional members as well.
See test PrimaryConstructor_01
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added test Alias_01
.
@@ -2281,6 +2299,11 @@ private BestSymbolInfo GetBestSymbolInfo(ArrayBuilder<Symbol> symbols, out BestS | |||
|
|||
private static BestSymbolLocation GetLocation(CSharpCompilation compilation, Symbol symbol) | |||
{ | |||
if (symbol is SourceMemberContainerTypeSymbol { IsFile: true }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we might, in some cases where the member access is not qualified. The only relevant case I can think of, though, involves using static
.
// File1.cs
using static C.D;
M();
file class C
{
public class D
{
public static void M() { }
}
}
// File2.cs
class C
{
public class D
{
public static void M() { }
}
}
I'll add the test. Let me know if any other scenarios come to mind that might hit this issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added this test and it "just worked". I suspect this is because we "broke the tie" when binding the using static C.D
, and binding the call is just a simple lookup within that.
src/Compilers/CSharp/Portable/SymbolDisplay/SymbolDisplayVisitor.Types.cs
Outdated
Show resolved
Hide resolved
return foundType is not null; | ||
} | ||
|
||
public static bool IsFileTypeInSeparateFileFrom(this SourceNamedTypeSymbol possibleFileType, SourceNamedTypeSymbol otherSymbol) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: do we think this will get re-used? If not consider making this a local function at single call-site
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought this might get reused in another place where we report redundant symbols, but it didn't end up being the case. Moving to local function.
{ | ||
public class C | ||
{ | ||
void M(Outer outer) { } // ok |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: consider adding void M2(C c) { } // ok
as well in this test (unless covered elsewhere)
} | ||
"""; | ||
|
||
var comp = CreateCompilation(new[] { source1, main }); // expectedOutput: 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM Thanks (iteration 14)
var model = comp.GetSemanticModel(tree, ignoreAccessibility: true); | ||
var cReference = tree.GetRoot().DescendantNodes().OfType<MemberAccessExpressionSyntax>().Last(); | ||
var info = model.GetTypeInfo(cReference); | ||
Assert.Equal(expectedSymbol.GetPublicSymbol(), info.Type); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we test base
references, in error scenarios?
// file1.cs
file class Base
{
public Base(int i) { }
}
partial class Derived : Base
{
}
// file2.cs
partial class Derived
{
Derived() : base(0) { }
}
// file1.cs
file class Base
{
public virtual void F1() { }
}
partial class Derived : Base
{
public override void F1() { }
}
// file2.cs
partial class Derived
{
void F2() { base.F1(); }
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to add these onto the test plan and add them in a subsequent PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a line to #60819.
src/Compilers/CSharp/Portable/Symbols/Source/SourceNamedTypeSymbol_Bases.cs
Outdated
Show resolved
Hide resolved
{ | ||
static void Main() | ||
{ | ||
Program.C.M(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The meaning of the program isn't changed, but the method of binding is changed. Here we lookup the symbols directly in the Program type rather than in a binder which contains the members of Program. I think I added this to address the issue discussed in #60977 (comment).
src/Compilers/CSharp/Test/Symbol/Symbols/Source/FileModifierTests.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Test/Symbol/Symbols/Source/FileModifierTests.cs
Outdated
Show resolved
Hide resolved
Failing tests are unrelated to my change. #61017 |
Related to #60819
I recommend disabling whitespace diffs when reviewing.
Implements the following sections of the spec (dotnet/csharplang#6011):
@jcouv @cston for review
I'm particularly wondering if the way I'm doing lookup, and the way I'm getting the "associated syntax tree" from a binder, is correct.