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-3066] Crash when using "as Any" to bind mutiple case statements in one. #45656

Open
swift-ci opened this issue Oct 28, 2016 · 2 comments
Open
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-3066
Radar None
Original Reporter Frain (JIRA User)
Type Bug
Environment

OSX 10.11.5 Xcode 8

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

md5: 10e424072ec1488a0545714cb098b421

Issue Description:

import Foundation

enum JSON {
  
  case object([String: Any])
  case array([Any])
  case any(Any)
  
  var object: Any {
    switch self {
    case .object(let any as Any):
      return any
    case .array(let any as Any):
      return any
    case .any(let any):
      return any
    default:
      return NSNull()
    }
  }
  
  var objectWillError: Any {
    switch self {
    case .object(let any as Any), .array(let any as Any), .any(let any):
      return any
    default:
      return NSNull()
    }
  }
}

JSON.object(["aaa": 222]).object
JSON.any(10).object

JSON.any(10).objectWillError

//The code below will be error

JSON.object(["aaa": 222]).objectWillError
@belkadan
Copy link
Contributor

@gregomni, was there another one like this?

@jdhealy
Copy link
Contributor

jdhealy commented Jun 29, 2017

Before closing SR-5336 as fixed, noticed this errors and no longer miscompiles in a recent toolchain:

{code:swift-DEVELOPMENT-SNAPSHOT-2017-06-12-a.xctoolchain errors:}
pbpaste | /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2017-06-12-a.xctoolchain/usr/bin/swiftc -sdk $(xcrun --show-sdk-path --sdk macosx) -emit-sil -
<stdin>:32:27: warning: expression of type 'Any' is unused
JSON.object(["aaa": 222]).object
~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
<stdin>:33:14: warning: expression of type 'Any' is unused
JSON.any(10).object
~~~~~~~~~~~~^~~~~
<stdin>:35:14: warning: expression of type 'Any' is unused
JSON.any(10).objectWillError
~~~~~~~~~~~~^~~~~~~~~~~~~~
<stdin>:39:27: warning: expression of type 'Any' is unused
JSON.object(["aaa": 222]).objectWillError
~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
<stdin>:24:22: error: matching a protocol value in multiple patterns is not yet supported; use separate cases instead
case .object(let any as Any), .array(let any as Any), .any(let any):
^

@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
Projects
None yet
Development

No branches or pull requests

3 participants