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-13842] Compiler fails to type check optional UIImage when SwiftUI is imported #56240

Closed
swift-ci opened this issue Nov 10, 2020 · 4 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-13842
Radar None
Original Reporter rog (JIRA User)
Type Bug
Status Closed
Resolution Duplicate

Attachment: Download

Environment

BigSur 11.0.1
Xcode 12.2 beta 4

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, TypeChecker
Assignee None
Priority Medium

md5: dfabfdcb3a7fd0eae9dbab6e92195d38

duplicates:

  • SR-13815 Confusing unwrapping diagnostic when using implicit member access on Optionals.

Issue Description:

Here's a minimum reproducible:

import UIKit
import SwiftUI

extension UIImage {
    static let background = UIImage(named: "test")
}

let b = UIImageView(image: .background)

The expectation here is that the compiler should be able to resolve .background to an optional UIImage, and accept it as the argument to initialize via UIIImageView(image: ).

However, when SwiftUI is imported in this context, the type checker fails with the following error message

Value of optional type 'UIImage?' must be unwrapped to a value of type 'UIImage'

The output of running

@swift-ci
Copy link
Collaborator Author

Comment by Frederick Kellison-Linn (JIRA)

Some breadcrumbs from brief investigation:

It appears that because `Optional` has a conditional conformance to `View`, our initial lookup pass for `background` (on `UIImage?`) finds `View.background(_:alignment🙂` on `Optional<UIImage>`. Then, when we reach the point in `ConstraintSystem::performMemberLookup` where we would normally look into `UIImage` for unresolved member lookup on an optional type, we've already found a candidate so we don't proceed...

@swift-ci
Copy link
Collaborator Author

Comment by Frederick Kellison-Linn (JIRA)

Here's a reproducer which doesn't touch SwiftUI at all.

extension Optional {
    func foo(_: Int) {}
}

struct S {}

extension S {
    static let foo: S? = S()
}

func takesS(_: S?) {}

takesS(.foo)

@typesanitizer
Copy link

Is this the same as https://bugs.swift.org/browse/SR-13815 ?

@swift-ci
Copy link
Collaborator Author

Comment by Frederick Kellison-Linn (JIRA)

theindigamer (JIRA User) Yes, that looks like the same issue!

@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 type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

2 participants