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-2302] Cannot infer type of .none for optional error type #44909

Open
karwa opened this issue Aug 9, 2016 · 2 comments
Open

[SR-2302] Cannot infer type of .none for optional error type #44909

karwa opened this issue Aug 9, 2016 · 2 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

@karwa
Copy link
Contributor

karwa commented Aug 9, 2016

Previous ID SR-2302
Radar None
Original Reporter @karwa
Type Bug
Environment

Swift 63a61e8

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

md5: 8bd4b26bbfdfc089b4cf747771048193

Issue Description:

  class A2 {
      public fileprivate(set) var error : Error? { 
          didSet { 
             if error != .none { 
                 print("Got error \(error)")
             } 
         } 
     } 
 } 

Produces the error:

error: repl.swift:10:16: error: cannot convert value of type 'Error?' to expected argument type '_?'
            if error != .none {
               ^~~~~
                     as! _?

A workaround is to compare to `nil` instead:

 class A2 { 
     public fileprivate(set) var error : Error? { 
         didSet { 
             if error != nil {
                 print("Got error \(error)") 
             } 
         } 
     } 
 } 
@karwa
Copy link
Contributor Author

karwa commented Aug 9, 2016

Or for optionals of classes:

class A {}
let a : A? = A()
if a != .none { print("expected") }
<REPL Input>:1:4: error: cannot convert value of type 'A?' to expected argument type '_?'
if a != .none { print("expected") }
   ^

@Dante-Broggi
Copy link
Contributor

This still occurs in the Xcode 9.4.1 toolchain.

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

No branches or pull requests

2 participants