Can public members inside an internal nested module be accessed outside the assembly in F#
26.5K reputation · 31 Jan 2020, 05:57 UTC
Designing an F# library with the goal of avoiding accidental public access requires clear understanding of how access modifiers compose for modules and nested types. Top-level modules and types are public by default, so internal is used to restrict them to the assembly. Nested modules and types default to private, visible only within the enclosing module or type unless explicitly marked internal or public.
Uncertainty about nested visibility
A documented nuance is that a nested module marked internal is invisible to external assemblies, while its members follow their own access modifiers. The internal keyword applied to a module does not change the visibility of its nested types; each nested type still follows its own modifier, which can lead to unexpected public exposure if not carefully annotated. The interaction between a private nested module that contains public members and runtime visibility is also unclear from official documentation, particularly regarding reflection-based access.
Which visibility rules apply to public members declared inside an internal nested module when the module itself is not visible outside the assembly? Does the module's internal modifier restrict access to those members for external consumers, or do the members remain reachable through metadata? How should library authors annotate nested modules and their members to guarantee no accidental public surface area?