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

Avoid resolving parameter.Type in ReportParameterErrors() #63142

Merged
merged 4 commits into from
Aug 9, 2022

Conversation

cston
Copy link
Member

@cston cston commented Aug 2, 2022

Fixes #63140

@cston cston requested a review from a team as a code owner August 2, 2022 20:18
@@ -648,7 +648,7 @@ static void addERR_ParamsCantBeWithModifier(BindingDiagnosticBag diagnostics, Sy
diagnostics.Add(ErrorCode.ERR_MethodArgCantBeRefAny, parameterSyntax.Location, parameter.Type);
}

if (parameter.Scope == DeclarationScope.ValueScoped && !parameter.Type.IsErrorTypeOrRefLikeType())
if (parameter.Scope == DeclarationScope.ValueScoped && !parameter.TypeWithAnnotations.IsRefLikeType())
Copy link
Member

@jcouv jcouv Aug 2, 2022

Choose a reason for hiding this comment

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

Is there a way to also check for the error type case without pulling too aggressively on lazy .Type? #Closed

Copy link
Member

Choose a reason for hiding this comment

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

Consider adding a comment at the top of this method that pulling on parameter.Type is cycle-prone.

Copy link
Member Author

@cston cston Aug 2, 2022

Choose a reason for hiding this comment

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

Is there a way to also check for the error type case without pulling too aggressively on lazy .Type?

We could add a similar IsErrorType() method to TypeWithAnnotations, but I'm not sure it's worth it. (Should an unresolved type always return false for IsErrorType()?)

Consider adding a comment ...

I've added a comment to the method to avoid using parameter.Type.

Copy link
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.

Done with review pass (iteration 1)

@@ -648,7 +651,7 @@ static void addERR_ParamsCantBeWithModifier(BindingDiagnosticBag diagnostics, Sy
diagnostics.Add(ErrorCode.ERR_MethodArgCantBeRefAny, parameterSyntax.Location, parameter.Type);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible for us to avoid using parameter.Type here as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think we're ok here because we've already checked that parameter.TypeWithAnnotations is a restricted type. That means the type is not a type parameter which is the only case where we'd have an unresolved type.

Copy link
Contributor

Choose a reason for hiding this comment

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

Will this break when we add allow T : ref struct? No need to adjust the implementation based on something we haven't done yet, but would be good to have a sense of what our path forward would be in that case.

Copy link
Member Author

Choose a reason for hiding this comment

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

Will this break when we add allow T : ref struct?

Yes, this will break when we support ref struct types as type arguments.

@cston cston requested a review from a team August 4, 2022 16:42
Copy link
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 3) but please hold off merging until after PR #62941 (runtime flag) was merged

@cston cston requested a review from a team August 8, 2022 15:38
@cston cston merged commit 35e54c1 into dotnet:main Aug 9, 2022
@cston cston deleted the 63140 branch August 9, 2022 19:44
@ghost ghost added this to the Next milestone Aug 9, 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.

Binder cycle leads to NullReferenceException
5 participants