-
Notifications
You must be signed in to change notification settings - Fork 4.2k
File types emit #61646
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 emit #61646
Changes from all commits
5b2db9e
99ab575
ad996eb
ffb137f
4600d6e
9dcff0c
86f8ffa
d37ce9f
6175fce
582709c
20efb7f
6ba8e19
ea89de4
59d5885
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,11 +2,14 @@ | |
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Collections.Immutable; | ||
| using System.Diagnostics; | ||
| using System.Linq; | ||
| using Microsoft.CodeAnalysis.CSharp.Symbols.Metadata.PE; | ||
| using Microsoft.CodeAnalysis.CSharp.Syntax; | ||
| using Microsoft.CodeAnalysis.PooledObjects; | ||
| using Microsoft.CodeAnalysis.Symbols; | ||
| using Roslyn.Utilities; | ||
|
|
||
|
|
@@ -243,6 +246,7 @@ internal virtual NamedTypeSymbol LookupMetadataType(ref MetadataTypeName emitted | |
| Debug.Assert(!emittedTypeName.IsNull); | ||
|
|
||
| NamespaceOrTypeSymbol scope = this; | ||
| Debug.Assert(scope is not MergedNamespaceSymbol); | ||
|
|
||
| if (scope.Kind == SymbolKind.ErrorType) | ||
| { | ||
|
|
@@ -326,6 +330,35 @@ internal virtual NamedTypeSymbol LookupMetadataType(ref MetadataTypeName emitted | |
| } | ||
|
|
||
| Done: | ||
| if (isTopLevel | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree that handling lookup for error cases quickly gets complicated :-/ Not blocking this PR, but it would be good to check what Aleksey thinks on supporting "correct" behavior of public APIs in error cases. #Closed
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It is not clear what specific scenarios we are talking about. Could you please elaborate?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @AlekseyTs The scenario is
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think in this case the file modifier on a nested type should be ignored and class D should be treated as a regular nested type. In other words, I think that the best implementation strategy here will be to not have nested file types in the symbol model, under no condition.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perfect. That's the approach Rikki took and it makes things simpler. Thanks @RikkiGibson If we take that approach, let's verify the symbol for class
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're going to add an item to test plan and ensure the 'IsFile' API behaves as described here in a subsequent PR. |
||
| && scope is not PENamespaceSymbol | ||
| && (emittedTypeName.ForcedArity == -1 || emittedTypeName.ForcedArity == emittedTypeName.InferredArity) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added test plan item |
||
| && GeneratedNameParser.TryParseFileTypeName( | ||
| emittedTypeName.UnmangledTypeName, | ||
RikkiGibson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| out string? displayFileName, | ||
| out int ordinal, | ||
| out string? sourceName)) | ||
| { | ||
| // also do a lookup for file types from source. | ||
| namespaceOrTypeMembers = scope.GetTypeMembers(sourceName); | ||
| foreach (var named in namespaceOrTypeMembers) | ||
| { | ||
| if (named.AssociatedSyntaxTree is SyntaxTree tree | ||
| && getDisplayName(tree) == displayFileName | ||
RikkiGibson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| && named.DeclaringCompilation.GetSyntaxTreeOrdinal(tree) == ordinal | ||
RikkiGibson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| && named.Arity == emittedTypeName.InferredArity) | ||
| { | ||
RikkiGibson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if ((object?)namedType != null) | ||
| { | ||
| namedType = null; | ||
RikkiGibson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| break; | ||
| } | ||
|
|
||
| namedType = named; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if ((object?)namedType == null) | ||
| { | ||
| if (isTopLevel) | ||
|
|
@@ -339,6 +372,13 @@ internal virtual NamedTypeSymbol LookupMetadataType(ref MetadataTypeName emitted | |
| } | ||
|
|
||
| return namedType; | ||
|
|
||
| static string getDisplayName(SyntaxTree tree) | ||
| { | ||
| var sb = PooledStringBuilder.GetInstance(); | ||
| GeneratedNames.AppendFileName(tree.FilePath, sb); | ||
| return sb.ToStringAndFree(); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.