Skip to content
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

Bind allows constraint clause #72386

Conversation

AlekseyTs
Copy link
Contributor

No description provided.

@AlekseyTs AlekseyTs requested review from jjonescz and cston March 4, 2024 23:19
@AlekseyTs AlekseyTs requested a review from a team as a code owner March 4, 2024 23:19
@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged Issues and PRs which have not yet been triaged by a lead label Mar 4, 2024
@AlekseyTs
Copy link
Contributor Author

@cston, @jjonescz, @dotnet/roslyn-compiler Please review

}
}

continue;
Copy link
Member

@jjonescz jjonescz Mar 5, 2024

Choose a reason for hiding this comment

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

Can we get here if hasRefStructConstraint is false and if so, should we report an error? #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can we get here if hasRefStructConstraint is false and if so, should we report an error?

I do not think it is possible to get such a tree from the parser. The syntax node description requires at least one item in the list. So, if someone somehow manages to create an allows clause with an empty list of constraints, that is on them and I am very comfortable to not report any errors about that. We generally do not guard against shapes that cannot come from our parser.

Copy link
Member

Choose a reason for hiding this comment

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

Makes sense, thanks. We probably don't want to have an assert here either, since one could create the tree manually, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We probably don't want to have an assert here either, since one could create the tree manually, right?

Right. The code is not making an assumption that the list is not empty. Therefore, having the assert is probably inappropriate.

{
if (inherited)
{
Location location = typeParameter.GetFirstLocation();
Copy link
Member

@jjonescz jjonescz Mar 5, 2024

Choose a reason for hiding this comment

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

I got the impression that getting location unnecessarily might be expensive - if that's true, could we pass typeParameter to the diagnostics instead? #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I got the impression that getting location unnecessarily might be expensive - if that's true, could we pass typeParameter to the diagnostics instead?

There is no overload that takes TypeParameterSymbol. A couple of conditions should be met before we get here. I don't think the situation is going to be very common and I prefer to not complicate the code until we have data indicating that there is a problem to fix.

@AlekseyTs
Copy link
Contributor Author

@cston, @dotnet/roslyn-compiler For the second review

<value>Target runtime doesn't support by-ref-like generics.</value>
</data>
<data name="ERR_RefStructConstraintAlreadySpecified" xml:space="preserve">
<value>The 'ref struct' is already specified.</value>
Copy link
Member

@cston cston Mar 5, 2024

Choose a reason for hiding this comment

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

The 'ref struct'

Perhaps just 'ref struct' is already specified rather than The 'ref struct' .... #Pending

{
}

public class C1 {}
Copy link
Member

@cston cston Mar 5, 2024

Choose a reason for hiding this comment

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

Consider removing unused type, in this test and the following test. #Pending

Assert.Equal("C1", t.ConstraintTypesNoUseSiteDiagnostics.Single().ToTestDisplayString());

Assert.True(t.AllowByRefLike);
}
Copy link
Member

@cston cston Mar 5, 2024

Choose a reason for hiding this comment

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

}

Consider testing:

class C<T, U>
    where T : allows ref struct
    where U : T, allows ref struct
{
}
``` #Pending

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Feature - RefStructInterfaces untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants