Skip to content

[SR-3505] Optional of a wrapped type with value nil is incorrectly considered to be an Optional of another wrapped type #46093

Closed
@swift-ci

Description

@swift-ci
Previous ID SR-3505
Radar None
Original Reporter goldsdad (JIRA User)
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment

OS X 10.11.6 (15G1212)
Xcode 8.2 (8C38)
IBM Swift Sandbox - Swift Ver. 3.0.2 (Release) - Platform: Linux (x86_64)

Additional Detail from JIRA
Votes 1
Component/s Standard Library
Labels Bug, TypeChecker
Assignee @slavapestov
Priority Medium

md5: e9915be07f69d31b7fe68a41773d1454

relates to:

  • SR-6192 Spurious "Cast from ... to unrelated type ... always fails" warning when implicitly converting an empty collection

Issue Description:

The output from the following code is reasonable to me except for the last line producing "true".

enum Foo<T> {  
    case some(T)  
    case none  
}  
  
print(  Foo<Int>.some(3) is Foo<Int>               ) // output: true  
print(  Foo<Int>.some(3) is Foo<String>            ) // output: false  
  
print(  Foo<Int>.none is Foo<Int>                  ) // output: true  
print(  Foo<Int>.none is Foo<String>               ) // output: false  
  
print(  Optional<Int>.some(3) is Optional<Int>     ) // output: true  
print(  Optional<Int>.some(3) is Optional<String>  ) // output: false  
  
print(  Optional<Int>.none is Optional<Int>        ) // output: true  
print(  Optional<Int>.none is Optional<String>     ) // output: true  

The compiler even issues warning "Cast from 'Optional<Int>' to unrelated type 'Optional<String>' always fails" for the last line, as it does for the lines producing "false", yet the result is "true".

Metadata

Metadata

Assignees

Labels

OptionalArea → standard library: The `Optional` typebugA deviation from expected or documented behavior. Also: expected but undesirable behavior.castingFeature: explicit casting (is, as, as? and as!)compilerThe Swift compiler itselftype checkerArea → compiler: Semantic analysis

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions