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

[SR-11054] “Expression failed to parse, unknown error” only in Xcode 10.2.1 playgrounds #53446

Open
swift-ci opened this issue Jul 2, 2019 · 2 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself PlaygroundTransform

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Jul 2, 2019

Previous ID SR-11054
Radar rdar://problem/52527289
Original Reporter TizianoCoroneo (JIRA User)
Type Bug
Environment

macOS Mojave 10.14.5

Xcode 10.2.1 Playgrounds

Swift 5.0

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, PlaygroundTransform
Assignee mattpat (JIRA)
Priority Medium

md5: 2012d30ee71bc653128fbacd64c97987

Issue Description:

Expression failed to parse, unknown error

The following code triggers this strange error message in the console area at the bottom of Xcode 10.2.1 Playgrounds.

class TestViewController: UIViewController {
    var mainLabel: UILabel!
}

class TestPresenter {
    init(_ vc: TestViewController) {
        self.vc = vc
    }
    
    var vc: TestViewController!
    
    func updateLabel(withString str: String) {
        vc.mainLabel.text = str
    }
}

The issue is fixed by or adding a question mark after mainLabel to make the optional chaining kick in:

class TestViewController: UIViewController {
    var mainLabel: UILabel!
}

class TestPresenter {
    init(_ vc: TestViewController) {
        self.vc = vc
    }
    
    var vc: TestViewController!
    
    func updateLabel(withString str: String) {
        vc.mainLabel?.text = str
    }
}

Or by removing the exclamation mark from the vc property, making the implicit optional unwrapping only one level deep instead of two:

class TestViewController: UIViewController {
    var mainLabel: UILabel!
}

class TestPresenter {
    init(_ vc: TestViewController) {
        self.vc = vc
    }
    
    var vc: TestViewController
    
    func updateLabel(withString str: String) {
        vc.mainLabel.text = str
    }
}

This error only appears in Xcode 10.2.1 Playgrounds. It compiles successfully in Xcode 10.2.1 projects. We also discussed this issue for a bit in the Swift forum here: https://forums.swift.org/t/expression-failed-to-parse-unknown-error-only-in-xcode-10-2-1-playgrounds

@belkadan
Copy link
Contributor

belkadan commented Jul 2, 2019

@swift-ci create

@dcci
Copy link
Mannequin

dcci mannequin commented Jul 18, 2019

This seems to be a Playgrounds issue.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself PlaygroundTransform
Projects
None yet
Development

No branches or pull requests

2 participants