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

Add rules for convenience method and protocol method #6934

Merged
merged 3 commits into from
Sep 28, 2023
Merged

Add rules for convenience method and protocol method #6934

merged 3 commits into from
Sep 28, 2023

Conversation

pshao25
Copy link
Member

@pshao25 pshao25 commented Sep 11, 2023

Overall, the logic is:
image

Regen PR: Azure/azure-sdk-for-net#38603

if (unwrappedType is INamedTypeSymbol responseTypeSymbol && responseTypeSymbol.IsGenericType)
{
var responseReturn = responseTypeSymbol.TypeArguments.Single();
if (responseReturn.Name != BooleanTypeName)
Copy link
Member

Choose a reason for hiding this comment

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

Just curious - why is Response<bool> special cased here?

Copy link
Member Author

Choose a reason for hiding this comment

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

If users set flag head-as-boolean, then the HEAD method will return Response<bool> instead of Response.

Comment on lines 152 to 155
if ((!IsOrImplements(typeSymbol, PageableTypeName)) && (!IsOrImplements(typeSymbol, AsyncPageableTypeName)))
{
return false;
}
Copy link
Member

Choose a reason for hiding this comment

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

Is this check necessary? If we ever return false here, it would be because we called this for the wrong method type. Both call sites to this method do the same if check before calling.

Copy link
Member Author

Choose a reason for hiding this comment

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

Emmm, I could remove it, but my initial thought is from the method IsValidPageable itself perspective, I should check if it is a pageable type because it is called IsValidPageable, otherwise if an operation type is passed mistakenly, it will still return true.

return;
}

if (!IsOrImplements(operationReturn, BinaryDataTypeName))
Copy link
Member

Choose a reason for hiding this comment

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

Does this mean operations can only return BinaryData types?

Copy link
Member Author

@pshao25 pshao25 Sep 26, 2023

Choose a reason for hiding this comment

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

Yes. You could see all the accepted return types from the comments of this method:

Response, Task<Response>, Response<bool>, Task<Response<bool>>, Pageable<BinaryData>, AsyncPageable<BinaryData>, Operation<BinaryData>, Task<Operation<BinaryData>>, Operation, Task<Operation>, Operation<Pageable<BinaryData>>, Task<Operation<AsyncPageable<BinaryData>>>

// A protocol method should not have model as parameter. If it has ambiguity with convenience method, it should have required RequestContext.
// Ambiguity: doesn't have a RequestContent, but there is a method ending with CancellationToken has same type of parameters
// No ambiguity: has RequestContent.
private static void CheckProtocolMethodParameters(ISymbolAnalysisContext context, IMethodSymbol method)
Copy link
Member

Choose a reason for hiding this comment

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

would a better name for this method be something like - CheckforAmbiguousMethodPair ?

Copy link
Member Author

Choose a reason for hiding this comment

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

But this method not only checks the ambiguity, but also the input parameters and output parameters of protocol methods.

@pshao25 pshao25 merged commit f05a61d into main Sep 28, 2023
14 checks passed
@pshao25 pshao25 deleted the addRules branch September 28, 2023 03:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants