-
Notifications
You must be signed in to change notification settings - Fork 472
Make syntax collections conform to ExpressibleByArrayLiteral
#336
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
Make syntax collections conform to ExpressibleByArrayLiteral
#336
Conversation
|
Without trying it myself, have you tried extension ExpressibleAsExprList: ExpressibleByArrayLiteral {
…
}or, if that doesn’t work, add the protocol conformance to Unrelated to this PR: I just realized that the standard library protocols are called ExpressibleBy and ours are called ExpressibleAs. Maybe we should change our protocols to also be called ExpressibleBy. |
Funny. I actually also noticed that yesterday when playing around with this 😆 |
9697a00 to
1d6a6fa
Compare
|
The problem is that protocols like: public protocol ExpressibleByConditionElement: ExpressibleByConditionElementList {
func createConditionElement() -> ConditionElement
}public protocol ExpressibleByConditionElementList: ExpressibleByArrayLiteral {
func createConditionElementList() -> ConditionElementList
}
There will come more of those cases as we add more conformances in protocols.py I think it will be best if we could make all syntax collections conform to this, and not just some of them. Second: We will have a |
|
This shouldn’t be an issue though if we implement |
I'm not sure I understand the question? Because I don't this this would be possible (I haven't tried it) public protocol ExpressibleByConditionElement {
init(arrayLiteral elements: Self.ArrayLiteralElement…) {
self. createConditionElement(self)
}
}Do we not need to call an |
|
I was thinking of something like this. // NEW: Add ExpressibleByArrayLiteral conformance here
protocol ExpressibleAsExprList : ExpressibleByArrayLiteral {}
protocol ExpressibleAsExprBuildable {}
// NEW: Generate this extension
extension ExpressibleAsExprList {
init(arrayLiteral elements: ExpressibleAsExprBuildable...) {
// self.init(elements) or something like this. `elements` has type `Array<ExpressibleAsExprBuildable>`
}
}
struct ExprList : ExpressibleAsExprList {}
struct ExprBuildable : ExpressibleAsExprBuildable {} |
We cannot access the When So I'm not sure how we don't need to implement the |
8f9f4cd to
da5de25
Compare
|
@swift-ci Please test |
|
Build failed |
|
Build failed |
da5de25 to
22a92c4
Compare
0463764 to
b5892bb
Compare
|
Sorry, I completely missed your comment. Thanks for pinging me. Of course, you’re right. We don’t want to be able to create an arbitrary extension ExprList: ExpressibleByArrayLiteral {
init(arrayLiteral elements: ExpressibleAsExprBuildable...) {
self.init(elements)
}
}This also matches your initial description of the PR where |
b5892bb to
ae96596
Compare
|
@swift-ci Please test |
|
Build failed |
|
Build failed |
ahoppen
left a comment
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.
Looks like a very nice addition to me.
ae96596 to
032639f
Compare
|
@swift-ci Please test |
|
Build failed |
032639f to
0102d5d
Compare
|
Build failed |
|
@swift-ci Please test Linux |
|
Build failed |
Initially I wanted to do something like
So we could remove
ExprListfrom places like here asconditions isExpressibleAsConditionElementList`But I got some compile errors I couldn't solve:
Conditional conformance of type 'Array<Element>' to protocol 'ExpressibleAsExprList' does not imply conformance to inherited protocol 'ExpressibleAsConditionElement'Conditional conformance of type 'Array<Element>' to protocol 'ExpressibleAsExprList' does not imply conformance to inherited protocol 'ExpressibleAsConditionElement'What I could figure out was that we need
extension Array: ExpressibleAsExprListto conform to all the protocols thatExpressibleAsExprListinheritance from. I could just figure out how to make that nice and cleanMaybe I will look into it later again if you don't have any idea, that could make it simple 😁
But I think this is an nice enhancement