Skip to content

Generate extensions for protocolsMap.py #339

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

Merged

Conversation

kimdv
Copy link
Contributor

@kimdv kimdv commented Nov 20, 2021

Generate extensions for protocolsMap.py.

Comment on lines -268 to -277
% for protocol, conformances in SYNTAX_BUILDABLE_EXPRESSIBLE_AS_CONFORMANCES.items():
% if 'ExpressibleAsConditionElementList' in conformances:
extension ${protocol} {
public func createConditionElementList() -> ConditionElementList {
ConditionElementList([self])
}
}

% end
% end
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one properly slipped through when added #334

% for conformance in conformances:
% node = NODE_MAP.get(conformance)
% if node and node.children:
% param = filter(lambda x : x.type_name != "TokenSyntax", node.children)[0].swift_name
Copy link
Member

Choose a reason for hiding this comment

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

I don’t think this is correct. We want to the first child that doesn’t have a default value. Currently optional children also have a default value of nil and TokenSyntax children might not have a default value if they don’t have a default text (see https://github.com/apple/swift/blob/17f1cf92973d2c1b3d5fe6b70f4a33771a303e3a/utils/gyb_syntax_support/kinds.py#L58-L64)

I think a better implementation would be

non_defaulted_params = filter(lambda child : syntax_buildable_default_init_value(child, SYNTAX_TOKEN_MAP.get(child.syntax_kind)) == None, node.children)
assert len(non_defaulted_params) == 1, "ExpressibleAs conformances expects the conforming type to have an initializer with a single non-optional child"
param = non_defaulted_params[0].swift_name

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I didn't see that.
Added. Tough changes the == None to == "" as we return an empty string.

@kimdv kimdv force-pushed the kimdv/generate-conformances-for-protocolmap branch from 2355440 to 8d74eda Compare November 22, 2021 10:29
@kimdv kimdv requested a review from ahoppen November 22, 2021 10:30
@kimdv
Copy link
Contributor Author

kimdv commented Nov 22, 2021

@swift-ci Please test

@ahoppen
Copy link
Member

ahoppen commented Nov 23, 2021

@swift-ci Please test

@kimdv kimdv merged commit d13d06a into swiftlang:main Nov 29, 2021
@kimdv kimdv deleted the kimdv/generate-conformances-for-protocolmap branch November 29, 2021 08:04
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.

2 participants