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-10123] Spurious warning about mutable struct #52525

Closed
swift-ci opened this issue Mar 17, 2019 · 4 comments
Closed

[SR-10123] Spurious warning about mutable struct #52525

swift-ci opened this issue Mar 17, 2019 · 4 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-10123
Radar rdar://problem/50625057
Original Reporter GarthSnyder (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Xcode 10.2 beta 4

macOS Mojave 10.14.4 beta (18E215a)

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

md5: aaad3849d944e1270ced5841c1eaea8d

is duplicated by:

  • SR-10646 “Variable was never mutated” warning on variable that is mutated
  • SR-11066 False positive "never mutated" warning when property with mutating getter is accessed on value

Issue Description:

Given the code below, the compiler generates a spurious warning as shown. It's important that the two fragments be in separate files.

// In file A.swift:
struct LazyStruct {
    lazy var value: Int = 42
}
 
// In file B.swift:
func test() {
    // Warning: Variable 'item' was never mutated; consider changing to 'let' constant
    var item = LazyStruct()
    print(item.value)
}

Of course, if you follow the compiler's advice and change item to be a let constant, it's no longer possible to access the lazy variable item.value and the compiler produces a hard error.

@belkadan
Copy link
Contributor

LValueAccessKind, anyone? cc @rjmccall, @slavapestov, @jckarter, @xedin

@slavapestov
Copy link
Member

Yeah, another reason to bring it back into the type checker (although the "never mutated" diagnostic never used it in the first place, it would need to in order to fix this issue).

@swift-ci
Copy link
Collaborator Author

Comment by Hanna Yakusevych (JIRA)

This issue has been fixed at least in 5.4.2, maybe earlier. GarthSnyder (JIRA User) Could you please verify using the 5.4.2 release toolchain, or 5.5 branch snapshot from swift.org?

@swift-ci
Copy link
Collaborator Author

Comment by Garth Snyder (JIRA)

Confirmed fixed in Xcode 13.0 beta (13A5155E), which I believe is toolchain 5.5.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 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 A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation
Projects
None yet
Development

No branches or pull requests

3 participants