-
Notifications
You must be signed in to change notification settings - Fork 10.5k
ASTPrinter: Mutability fixes for protocol stubs #24277
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
Changes from all commits
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 |
---|---|---|
|
@@ -2627,6 +2627,15 @@ printRequirementStub(ValueDecl *Requirement, DeclContext *Adopter, | |
Options.FunctionDefinitions = true; | ||
Options.PrintAccessorBodiesInProtocols = true; | ||
|
||
// Skip 'mutating' only inside classes: mutating methods usually | ||
// don't have a sensible non-mutating implementation. | ||
bool isClass = Adopter->getSelfClassDecl() != nullptr; | ||
if (isClass) | ||
Options.ExcludeAttrList.push_back(DAK_Mutating); | ||
// 'nonmutating' is only meaningful on value type member accessors. | ||
if (isClass || !isa<AbstractStorageDecl>(Requirement)) | ||
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 don't think this qualification is necessary. You're not allowed to write 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.
Am I? 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. Um. It doesn't even make sense for protocol requirements, but you're right that it's not rejected. I did not realize that. 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.
Oh, right, of course. |
||
Options.ExcludeAttrList.push_back(DAK_NonMutating); | ||
|
||
// FIXME: Once we support move-only types, remove this if the | ||
// conforming type is move-only. Until then, don't suggest printing | ||
// __consuming on a protocol requirement. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
public protocol ExternalMutabilityProto { | ||
mutating func foo() | ||
subscript() -> Int { mutating get nonmutating set } | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this part not relevant? I assumed it kept
mutating
from being printed twice in some cases.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not anymore I believe, since I chose to skip mutability modifiers in
printAttributes
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI this caused interface generation to print
mutating mutating
for explicitly mutating functions, because the changes made toprintAttributes
only applied to implicit attributes. Fixed: #30183