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

Swift 4.1 issue discovered around Structs with two Strings #3646

Closed
eweiter opened this issue May 11, 2018 · 4 comments
Closed

Swift 4.1 issue discovered around Structs with two Strings #3646

eweiter opened this issue May 11, 2018 · 4 comments

Comments

@eweiter
Copy link
Contributor

eweiter commented May 11, 2018

It was reported that the Swift 4.1 runtime was exhibiting a strange behavior. The behavior in question occurs when a Struct has multiple Strings and those Strings are being initialized directly from static Strings.

For instance, the following piece of code will work:

struct Output: Codable {
    let greeting: String
    let group: String
}
func main(completion: (Output?, Error?) -> Void) -> Void {
    let name = "MyName"
    let result = Output(greeting: "Hello \(name)", group: "Greetings")
    print("Log greeting:\(result.greeting)")
    completion(result, nil)
}

However the following code will not:

struct Output: Codable {
    let greeting: String
    let group: String
}
func main(completion: (Output?, Error?) -> Void) -> Void {
    let result = Output(greeting: "Hello Name", group: "bummer")
    print("Log greeting:\(result.greeting)")
    completion(result, nil)
}

It appears to be a bug within Swift itself.
We have discovered that if the code is compiled with the compiler flag to turn off optimizations then the compiling will work. This compile flag is -Xswiftc -Onone

@eweiter
Copy link
Contributor Author

eweiter commented May 13, 2018

PR #3647 was merged as a temp fix until the issue is addressed in the Swift Docker image.

@eweiter
Copy link
Contributor Author

eweiter commented May 15, 2018

I believe I have narrowed down the reasoning for this issue as coming from the use of the "@escaping" syntax in here https://github.com/apache/incubator-openwhisk-runtime-swift/blob/master/core/swift41Action/epilogue.swift#L98

I have stripped down this code the mainly the essentials (non-whisk related) items and when the "@escaping" option is present the code will throw a compiler error, however when I remove the statement the code will compile fine and execute successfully.

I will be opening an issue against the Swift Docker image tomorrow and will link that here when I do.

@csantanapr csantanapr reopened this May 15, 2018
@csantanapr
Copy link
Member

leaving open until we get a fix from swift team

@csantanapr
Copy link
Member

Issue moved to apache/incubator-openwhisk-runtime-swift #60 via ZenHub

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

2 participants