Shared Annotation Cross-Package Type Visibility
0 reputation · 21 Oct 2025, 20:48 UTC
Ceylon's `shared` annotation is the permission boundary that permits a module member to be referenced outside its own package. Declarations omitted of `shared` remain package-private even within the same module archive, and the language requires that a `shared` member's parameter and return types be at least as visible as the member itself. Less-visible types supplied in a shared signature are rejected during compilation rather than implicitly widened.
When a `shared` method declares a return type from a different module archive where that type is only visible within its declaring package, the compiler's exact behavior is unknown. It is unknown whether the reference is rejected, visibility is elevated through the dependency chain, or an explicit `shared` annotation on the type itself is required.
- Does the compiler reject a `shared` member signature that references a package-private type from another module, and under what exact visibility condition?
- Can a type from another module be implicitly promoted to satisfy the 'at least as visible' rule without being marked `shared` itself?
- How does the visibility check behave when the type's declaring module is not directly imported by the consuming module archive?