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-14434] [TSPL] Provide examples of opaque type not exposing the underlying type #56790

Open
typesanitizer opened this issue Mar 31, 2021 · 1 comment

Comments

@typesanitizer
Copy link

Previous ID SR-14434
Radar rdar://problem/76063010
Original Reporter @typesanitizer
Type Improvement
Additional Detail from JIRA
Votes 0
Component/s
Labels Improvement, Documentation
Assignee None
Priority Medium

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 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.

@typesanitizer
Copy link
Author

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

No branches or pull requests

1 participant