Skip to content

Improve circularity analysis in bases for some scenarios.#62799

Merged
333fred merged 2 commits intodotnet:mainfrom
AlekseyTs:Issue58424
Jul 28, 2022
Merged

Improve circularity analysis in bases for some scenarios.#62799
333fred merged 2 commits intodotnet:mainfrom
AlekseyTs:Issue58424

Conversation

@AlekseyTs
Copy link
Copy Markdown
Contributor

Fixes #58424.
Fixes #62795.

@AlekseyTs AlekseyTs requested a review from a team as a code owner July 20, 2022 19:26
@AlekseyTs
Copy link
Copy Markdown
Contributor Author

@dotnet/roslyn-compiler For the second review

@AlekseyTs
Copy link
Copy Markdown
Contributor Author

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 4 pipeline(s).

@AlekseyTs
Copy link
Copy Markdown
Contributor Author

@dotnet/roslyn-compiler For the second review

2 similar comments
@AlekseyTs
Copy link
Copy Markdown
Contributor Author

@dotnet/roslyn-compiler For the second review

@AlekseyTs
Copy link
Copy Markdown
Contributor Author

@dotnet/roslyn-compiler For the second review

@jcouv jcouv self-assigned this Jul 28, 2022

[Fact]
[WorkItem(58424, "https://github.com/dotnet/roslyn/issues/58424")]
public void NestedTypes_53()
Copy link
Copy Markdown
Member

@jcouv jcouv Jul 28, 2022

Choose a reason for hiding this comment

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

📝 This comment in the bug was helpful for reviewers to understand the bug:

The error is reported because, while binding Test's bases, we are binding IInner's bases as well. Lookup triggers that binding while resolving "IOuter", it tries to look for this name within IInner's bases, that tries to resolve the "Other" and the error is reported once we try to look it up within Test, which needs Test's bases and the circle completes.

In the particular scenario we can avoid an attempt to lookup "IOuter" within IInner's bases because, we first look in the IInner itself (without inheritance). If we found the type there, no reason to look for it in IInner's bases, anything found will be shadowed by the immediate result anyway. BTW, the shadowing check causes a stack overflow, see #62795.

Avoiding the error in a more general case is likely to add more complexity to circularity analysis in bases. Not sure if it is worth it. #Resolved

{
b.OriginalDefinition.AddUseSiteInfo(ref useSiteInfo);

if (TypeSymbol.Equals(b, baseType, TypeCompareKind.ConsiderEverything2))
Copy link
Copy Markdown
Member

@jcouv jcouv Jul 28, 2022

Choose a reason for hiding this comment

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

nit: Can we avoid introducing new usage of ConsiderEverything2?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Can we avoid introducing new usage of ConsiderEverything2?

This line of code is a clone of an existing line in the same function. Figuring out appropriate mode of comparison and adding related tests was outside of scope of this PR.

Copy link
Copy Markdown
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

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

LGTM Thanks (iteration 2) with a nit

@333fred 333fred merged commit d905b97 into dotnet:main Jul 28, 2022
@ghost ghost added this to the Next milestone Jul 28, 2022
@dibarbet dibarbet modified the milestones: Next, 17.4 P2 Sep 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stack overflow in lookup Wrong circular base type dependency errors on nested type inheritance

4 participants