Skip to main content
fix if statements
Source Link
zombie
  • 5.3k
  • 3
  • 28
  • 57

When you use multiple patterns in a single case of a switch, they must bind all of the same variables.

Swift sees this line:

case (let c as C, 4), let nonNilSpecific as? String: 

and thinks you're trying to match either (let c as C, 4) or let nonNilSpecific as? String. Those two choices bind different variables, so in the case body it is impossible to know which variables have been bound.

Perhaps you wanted something like this:

switch (unknown, unknown.common) { case (let a as A, 4): break case (let b as B, 4): break case (let c as C, 4) where c.specific != nil: // force unwrap safe here, no closure needed let nonNilSpecific = c.specific! default: break } 

Use an if:

let tuple = (unknown, unknowunknown.common) if case (let a as A, 4) = tuple { // use a } else if case (let b as B, 4) = tuple { // use b } else if case (let c as C, 4) = tuple, let nonNilSpecific = c.specific { // use c and nonNilSpecific } else { // default case } 

When you use multiple patterns in a single case of a switch, they must bind all of the same variables.

Swift sees this line:

case (let c as C, 4), let nonNilSpecific as? String: 

and thinks you're trying to match either (let c as C, 4) or let nonNilSpecific as? String. Those two choices bind different variables, so in the case body it is impossible to know which variables have been bound.

Perhaps you wanted something like this:

switch (unknown, unknown.common) { case (let a as A, 4): break case (let b as B, 4): break case (let c as C, 4) where c.specific != nil: // force unwrap safe here, no closure needed let nonNilSpecific = c.specific! default: break } 

Use an if:

let tuple = (unknown, unknow.common) if case (let a as A, 4) = tuple { // use a } else if case (let b as B, 4) = tuple { // use b } else if case (let c as C, 4), let nonNilSpecific = c.specific { // use c and nonNilSpecific } else { // default case } 

When you use multiple patterns in a single case of a switch, they must bind all of the same variables.

Swift sees this line:

case (let c as C, 4), let nonNilSpecific as? String: 

and thinks you're trying to match either (let c as C, 4) or let nonNilSpecific as? String. Those two choices bind different variables, so in the case body it is impossible to know which variables have been bound.

Perhaps you wanted something like this:

switch (unknown, unknown.common) { case (let a as A, 4): break case (let b as B, 4): break case (let c as C, 4) where c.specific != nil: // force unwrap safe here, no closure needed let nonNilSpecific = c.specific! default: break } 

Use an if:

let tuple = (unknown, unknown.common) if case (let a as A, 4) = tuple { // use a } else if case (let b as B, 4) = tuple { // use b } else if case (let c as C, 4) = tuple, let nonNilSpecific = c.specific { // use c and nonNilSpecific } else { // default case } 
deleted 19 characters in body
Source Link
vacawama
  • 155.1k
  • 32
  • 283
  • 315

When you use multiple patterns in a single case of a switch, they must bind all of the same variables.

Swift sees this line:

case (let c as C, 4), let nonNilSpecific as? String: 

and thinks you're trying to match either (let c as C, 4) or let nonNilSpecific as? String. Those two choices bind different variables, so in the case body it is impossible to know which variables have been bound.

Perhaps you wanted something like this:

switch (unknown, unknown.common) { case (let a as A, 4): break case (let b as B, 4): break case (let c as C, 4) where c.specific != nil: let nonNilSpecific =// c.specific! force unwrap safe here, //no useclosure nonNilSpecificneeded  WITHOUT unwrap it withinlet thenonNilSpecific case= clousrec.specific! default: break } 

Use an if:

let tuple = (unknown, unknow.common) if case (let a as A, 4) = tuple { // use a } else if case (let b as B, 4) = tuple { // use b } else if case (let c as C, 4), let nonNilSpecific = c.specific { // use c and nonNilSpecific } else { // default case } 

When you use multiple patterns in a single case of a switch, they must bind all of the same variables.

Swift sees this line:

case (let c as C, 4), let nonNilSpecific as? String: 

and thinks you're trying to match either (let c as C, 4) or let nonNilSpecific as? String. Those two choices bind different variables, so in the case body it is impossible to know which variables have been bound.

Perhaps you wanted something like this:

switch (unknown, unknown.common) { case (let a as A, 4): break case (let b as B, 4): break case (let c as C, 4) where c.specific != nil: let nonNilSpecific = c.specific!  // use nonNilSpecific WITHOUT unwrap it within the case clousre default: break } 

Use an if:

let tuple = (unknown, unknow.common) if case (let a as A, 4) = tuple { // use a } else if case (let b as B, 4) = tuple { // use b } else if case (let c as C, 4), let nonNilSpecific = c.specific { // use c and nonNilSpecific } else { // default case } 

When you use multiple patterns in a single case of a switch, they must bind all of the same variables.

Swift sees this line:

case (let c as C, 4), let nonNilSpecific as? String: 

and thinks you're trying to match either (let c as C, 4) or let nonNilSpecific as? String. Those two choices bind different variables, so in the case body it is impossible to know which variables have been bound.

Perhaps you wanted something like this:

switch (unknown, unknown.common) { case (let a as A, 4): break case (let b as B, 4): break case (let c as C, 4) where c.specific != nil: // force unwrap safe here, no closure needed  let nonNilSpecific = c.specific! default: break } 

Use an if:

let tuple = (unknown, unknow.common) if case (let a as A, 4) = tuple { // use a } else if case (let b as B, 4) = tuple { // use b } else if case (let c as C, 4), let nonNilSpecific = c.specific { // use c and nonNilSpecific } else { // default case } 
added 359 characters in body
Source Link
vacawama
  • 155.1k
  • 32
  • 283
  • 315

When you use multiple patterns in a single case of a switch, they must bind all of the same variables.

Swift sees this line:

case (let c as C, 4), let nonNilSpecific as? String: 

and thinks you're trying to match either (let c as C, 4) or let nonNilSpecific as? String. Those two choices bind different variables, so in the case body it is impossible to know which variables have been bound.

Perhaps you wanted something like this:

switch (unknown, unknown.common) { case (let a as A, 4): break case (let b as B, 4): break case (let c as C, 4) where c.specific != nil: let nonNilSpecific = c.specific! // use nonNilSpecific WITHOUT unwrap it within the case clousre default: break } 

Use an if:

let tuple = (unknown, unknow.common) if case (let a as A, 4) = tuple { // use a } else if case (let b as B, 4) = tuple { // use b } else if case (let c as C, 4), let nonNilSpecific = c.specific { // use c and nonNilSpecific } else { // default case } 

When you use multiple patterns in a single case, they must bind all of the same variables.

Swift sees this line:

case (let c as C, 4), let nonNilSpecific as? String: 

and thinks you're trying to match either (let c as C, 4) or let nonNilSpecific as? String. Those two choices bind different variables, so in the case body it is impossible to know which variables have been bound.

Perhaps you wanted something like this:

switch (unknown, unknown.common) { case (let a as A, 4): break case (let b as B, 4): break case (let c as C, 4) where c.specific != nil: let nonNilSpecific = c.specific! // use nonNilSpecific WITHOUT unwrap it within the case clousre default: break } 

When you use multiple patterns in a single case of a switch, they must bind all of the same variables.

Swift sees this line:

case (let c as C, 4), let nonNilSpecific as? String: 

and thinks you're trying to match either (let c as C, 4) or let nonNilSpecific as? String. Those two choices bind different variables, so in the case body it is impossible to know which variables have been bound.

Perhaps you wanted something like this:

switch (unknown, unknown.common) { case (let a as A, 4): break case (let b as B, 4): break case (let c as C, 4) where c.specific != nil: let nonNilSpecific = c.specific! // use nonNilSpecific WITHOUT unwrap it within the case clousre default: break } 

Use an if:

let tuple = (unknown, unknow.common) if case (let a as A, 4) = tuple { // use a } else if case (let b as B, 4) = tuple { // use b } else if case (let c as C, 4), let nonNilSpecific = c.specific { // use c and nonNilSpecific } else { // default case } 
added 1 character in body
Source Link
vacawama
  • 155.1k
  • 32
  • 283
  • 315
Loading
added 308 characters in body
Source Link
vacawama
  • 155.1k
  • 32
  • 283
  • 315
Loading
Source Link
vacawama
  • 155.1k
  • 32
  • 283
  • 315
Loading