You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The chapter on opaque types describes what you can do with them, it would be helpful to also include 1-2 examples of what you can't do with them.
We get asked such questions on a semi-regular basis. For example, https://bugs.swift.org/browse/SR-14415. There's a bunch of good discussion in the thread, here's what I wrote for why the underlying type is not exposed:
The compiler does "know" the type, however it deliberately doesn't expose the type because those are the language semantics – if you wrote an opaque return type, that means you want to be able to change the underlying type in the future without breaking callers. If callers were able to access the opaque return type's underlying type, then that code would break if you changed the function's body.
This also helps preserve the language property that changing the body of a function without changing its signature shouldn't affect the callers of that function.
The text was updated successfully, but these errors were encountered:
Additional Detail from JIRA
md5: b99508f82ae58e121cad77764808b95f
Issue Description:
The chapter on opaque types describes what you can do with them, it would be helpful to also include 1-2 examples of what you can't do with them.
We get asked such questions on a semi-regular basis. For example, https://bugs.swift.org/browse/SR-14415. There's a bunch of good discussion in the thread, here's what I wrote for why the underlying type is not exposed:
The text was updated successfully, but these errors were encountered: