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-13838] S? is not regarded as Optional<S> in "case" expression. #56236

Open
YOCKOW opened this issue Nov 10, 2020 · 1 comment
Open

[SR-13838] S? is not regarded as Optional<S> in "case" expression. #56236

YOCKOW opened this issue Nov 10, 2020 · 1 comment
Labels
compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis

Comments

@YOCKOW
Copy link
Collaborator

YOCKOW commented Nov 10, 2020

Previous ID SR-13838
Radar rdar://problem/71296526
Original Reporter @YOCKOW
Type Sub-task
Environment

OS: macOS Catalina 10.15.7, Ubuntu 20.04.01
Swift: 5.3

Additional Detail from JIRA
Votes 1
Component/s Compiler
Labels Sub-task, TypeChecker
Assignee None
Priority Medium

md5: d252187472e82df4f2680e9b59d248fb

Parent-Task:

  • SR-14407 ☂️ Inconsistent behavior between sugared types and desugared types

is duplicated by:

  • SR-14598 Optional unexpectedly behaves differently from Any?

Issue Description:

Given the following code, the compiler views errors in the last switch statement.

struct S {}

let optional: Optional<S> = Bool.random() ? S?.none : S?.some(S()) // OK

switch optional {
case nil: // OK
  print("It's nil")
case _?: // OK
  print("It's not nil")
}

switch optional {
case Optional<S>.none: // OK
  print("It's nil")
case Optional<S>.some: // OK
  print("It's not nil")
}

switch optional {
case S?.none: // Error: Operator function '~=' requires that 'S' conform to 'Equatable'
  print("It's nil")
case S?.some: // Error: Expression pattern of type '(S) -> Optional<S>' cannot match values of type 'Optional<S>'
              // Error: operator function '~=' requires that 'S' conform to 'Equatable'
  print("It's not nil")
}
@typesanitizer
Copy link

@swift-ci create

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

No branches or pull requests

2 participants