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

Suggestion: restrict "private" for items in namespaces to mean "private to the namespace declaration group" #43

Closed
KevinRansom opened this issue Jan 18, 2015 · 3 comments

Comments

@KevinRansom
Copy link
Member

Opened at CodePlex by ovatsus

This should give a compile time error, but doesn't:
[File1.fs]

namespace MyApp

module private Module1 =
    let f x = x

[Program.fs]

namespace MyApp

module Module2 =
    open Module1
    let y = f 1

    do
        printfn "%O" y

When evaluating in fsx the error is correctly issued

@latkin latkin added the Bug label Jan 19, 2015
@latkin
Copy link
Contributor

latkin commented Jan 19, 2015

@dsyme - related to https://visualfsharp.codeplex.com/workitem/29 and/or #27 ?

@dsyme
Copy link
Contributor

dsyme commented Jan 20, 2015

For F# 4.0 (and F# 3.x) it seems best to resolve this as by design. In F#, "private" means "private to the enclosing module or type". However, the meaning of "private" for a construct in a namespace needs clarification.

The F# Language Spec for F# 2.x-4.0 will be adjusted to clarify that "private" on a type or module in a namespace declaration group "namespace N = " means "accessible from that namespace declaration group, or any namespace declaration group in the same assembly contributing to either N of a sub-namespace of N." This means that a private construct in namespace N is accessible from all other namespace declaration groups in the same assembly contributing to N.

I understand that this is a weaker form of "private" than simply "private to the encloding namespace declaration group" or "private to the file". However, it is as F# 2.0-3.x has always implemented. Any adjustment to restrict this is surprisingly non-trivial, partly because we must give a warning for existing uses, rather than an error. This needs a lot of care beyond what I'd like to see for F# 4.0 at this stage.

I've added an F# Language User Voice suggestion suggesting we consider restricting this in future versions of F#.

(BTW the only other modification that looks reasonable here for F# 4.0 would be to simply give a warning to recommend that people use "internal" rather than "private" for types and modules in namespaces)

@dsyme dsyme changed the title Private module doesn't give compilation error when inner functions inappropriately accessed Suggestion: restrict "private" for items in namespaces to mean "private to the namespace declaration group" Jan 20, 2015
@dsyme
Copy link
Contributor

dsyme commented Jul 18, 2016

Tracked by the user voice request

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

3 participants