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-2989] Multi-line function chains evaluated before breakpoint hits #4581

Closed
swift-ci opened this issue Oct 19, 2016 · 3 comments
Closed
Assignees
Labels
bug Something isn't working LLDB for Swift

Comments

@swift-ci
Copy link

Previous ID SR-2989
Radar rdar://28883410
Original Reporter rosslebeau (JIRA User)
Type Bug
Status Resolved
Resolution Won't Do
Environment

Swift 3.0
macOS 10.12 16A323

Additional Detail from JIRA
Votes 1
Component/s LLDB for Swift
Labels Bug
Assignee @vedantk
Priority Medium

md5: b5bc35bd9978fec0d64c651b37689c3f

Issue Description:

In certain cases, if you have a multi-line function chain, placing a breakpoint on the first line will actually result in the function chain being evaluated before the breakpoint hits.

For example:

func printMarker(_ x: Int) -> Int {
    print("marker")
    return x
}

struct User {
    let name: String
    let age: Int
}

struct Message {
    func mentionedUsersF() -> [User] {
        return [User(name: "Achilles", age: 32), User(name: "Tortoise", age: 105)]
    }
}

let message = Message()

var ages: [Int]

ages = [1, 2, 3]

ages = message
    .mentionedUsersF()
    .map { $0.age }
    .map(printMarker)

print(ages)

Place a breakpoint on the `ages = message` line, and you will see that "marker" has been printed at the time of breaking. The `ages` variable is still equal to `[1, 2, 3]`, however, so it hasn't been set yet.

This also occurs if you use a computed property instead of a function.

This does not happen if:

  • Any of the function calls are moved up to the first line

  • The struct contains a non-computed property (it can be unused, as long as there is one)

  • A class is used instead of struct

  • Functions that are not members of a struct are used instead

@belkadan
Copy link

@adrian-prantl, granataenrico (JIRA User), what do you think?

@adrian-prantl
Copy link
Member

From the description this definitely sounds like a compiler bug.

@vedantk
Copy link
Member

vedantk commented Apr 18, 2018

I looked into this recently and found that there isn't a good way to address this problem.

Any fix that enables stepping on the line "ages = message" prior to a call to map would result in inconsistent stepping behavior between Swift and C-based languages. Further, it might result in spurious extra stepping onto lines which just contain a reference to a decl.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 7, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working LLDB for Swift
Projects
None yet
Development

No branches or pull requests

4 participants