Skip to content

Instantly share code, notes, and snippets.

@mfaani
Last active September 30, 2024 18:09
Show Gist options
  • Save mfaani/183c334a75eb5f5e6d35d577a09d5b4f to your computer and use it in GitHub Desktop.
Save mfaani/183c334a75eb5f5e6d35d577a09d5b4f to your computer and use it in GitHub Desktop.
`some Equatable` vs another `some Equatable`
var a: some Equatable = 10
var c: some Equatable = 10
a = c // ERROR: Cannot assign value of type 'some Equatable' (type of 'c') to type 'some Equatable' (type of 'a')

You can't pass a different some Equatable to a. The compiler can't guarantee if a and c have identical underlying concrete types. Even though on the screen you can see c is an Int, to the compiler it's just some Equatable. It's NOT some Equatable_But_really_an_Int.

Because it's some Equatable then the compiler would be like, then 'What if c was "ten"? Let's just be safe an not allow it'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment