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

Xcode 10 Swift optional chaining bug #204

Open
MarcoFiletti opened this issue Nov 27, 2018 · 2 comments
Open

Xcode 10 Swift optional chaining bug #204

MarcoFiletti opened this issue Nov 27, 2018 · 2 comments

Comments

@MarcoFiletti
Copy link

Issue Info

Info Value
Platform Name iOS
Platform Version 11.4
Integration Method CocoaPods
Xcode Version Xcode 10 (does not apply to Xcode 9)
Repro rate 100%
Demo project link See code below

Issue Description and Steps

Hello, I'm wondering why optional chaining (in a Swift project, integrated with CocoaPods) always fails by returning nil. However, step-by-step (or chaining done in the debugger) works. For example, try this:

let set = JWTClaimsSet()
set.issuer = "testIssuer"
set.subject = "testSubjectx"
        
let secret = "aaabbbcccddd"
        
let heads = ["customKey": "customValue"]
        
let algo = JWTAlgorithmHSBase.algorithm384()
        
let e = JWTBuilder.encode(set)!
let h = e.headers(heads)!
let s = h.secret(secret)!
let b = s.algorithm(algo)!
let enc = b.encode
        
guard let encoded = enc else {
    fatalError("No encoded")
}
        
print(encoded)  // succeeds

print("success")  // note that if we insert a breakpoint here and run `po JWTBuilder.encode(set)?.headers(heads)?.secret(secret)?.algorithm(algo)?.encode` we get a non-nil value

guard let encoded2 = JWTBuilder.encode(set)?.headers(heads)?.secret(secret)?.algorithm(algo)?.encode else {
   fatalError("No encoded 2")  // fails
}
        
print(encoded2)

Note that this only happens in Xcode 10 (not 9) so maybe it's a compiler bug?

@michaelspecht
Copy link

I'm seeing this on Xcode 10.1 as well on the latest release (3.0.0-beta.11, though it was happening on 3.0.0-beta.5 as well)

@lolgear
Copy link
Collaborator

lolgear commented Jun 15, 2019

@MarcoFiletti @michaelspecht
Hi!
I have figure out what is going on. It is a swift correct behavior with fluent-ish blocks that captures weakSelf.
It is fixed in latest master for Version 3 only.

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

No branches or pull requests

3 participants