You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
enum A {}
struct MyStruct {
var a: A
}
func myFunc(_: inout A) {}
func myOtherFunc(s: inout MyStruct) {
myFunc(&s.a)
}
This is compliable code in swiftc.
Our point of concern is the use of an in-out expression as a parameter in the call to myFunc
There is no possible derivation of this subsection of the code given the production for in-out-expression with identifier rather than expression.
Let us look at some possible derivation paths for myFunc(&s.a)
Thanks! This change looks like it's probably correct, but I'll need to find someone who can tech review to confirm this is exactly the expected behavior.
The old grammar didn't allow things like f(&x.y) which are legal in
Swift. The new grammar allows a bunch of extra stuff -- literals,
closures, and conditional expressions -- but that's a better problem to
have.
See also #194, where we're discussing a more specific fix.
Fixes: #193 (partially)
Location
https://github.com/apple/swift-book/blob/main/TSPL.docc/ReferenceManual/Expressions.md?plain=1#L64
Description
An in-out-expression is defined as being & identifier.
This is incorrect, and can be seen on line 51 that it's meant to be & expression. (here: https://github.com/apple/swift-book/blob/main/TSPL.docc/ReferenceManual/Expressions.md?plain=1#L51)
I'm assuming this is just a simple error that was overlooked but I will leave a demonstration below of why the version with identifier isn't correct.
Given this example program:
This is compliable code in swiftc.
Our point of concern is the use of an in-out expression as a parameter in the call to myFunc
There is no possible derivation of this subsection of the code given the production for in-out-expression with identifier rather than expression.
Let us look at some possible derivation paths for
myFunc(&s.a)
Possible derivation path: (terminals in bold)
???- cannot reach a production that will get us &s
Let's look at another possible derivation path.
Picking up from step 12 in the above derivation:
12) -> myFunc ( prefix-expression infix-expressions? )
13) -> myFunc ( in-out-expression infix-expressions? )
14) -> myFunc ( & identifier infix-expressions? )
15) -> myFunc ( & ??? infix-expressions? )
???- cannot reach a production that will get us &s.a
Correction
Line 64 should read in-out-expression →
&
expressionThe text was updated successfully, but these errors were encountered: