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

Cannot use operators defined in internal types. #16762

Open
teo-tsirpanis opened this issue Feb 26, 2024 · 3 comments
Open

Cannot use operators defined in internal types. #16762

teo-tsirpanis opened this issue Feb 26, 2024 · 3 comments
Labels
Area-Compiler-Checking Type checking, attributes and all aspects of logic checking Bug Impact-Low (Internal MS Team use only) Describes an issue with limited impact on existing code.
Milestone

Comments

@teo-tsirpanis
Copy link
Contributor

I discovered that the compiler will not let me use an operator in an internal type, even from an internal function. I'm not sure if it's intentional, so opening it here as a bug.

Repro steps

open System

module internal M =
    type C(value: int) =
        static member inline (||+) (x: C, y: C) = 0
    
let inline internal f (x1: M.C) (x2: M.C) = x1 ||+ x2

Expected behavior

The snippet compiles successfully.

Actual behavior

error FS0043: The member or object constructor 'op_BarBarPlus' is not public. Private members may only be accessed from within the declaring type. Protected members may only be accessed from an extending type and cannot be accessed from inner lambda expressions.

Known workarounds

If I make the module public the snippet will compile successfully. I can do it in my use case (an F# library distributed in source form) and explicitly document that the types may become internal at any time.

Related information

Provide any related information (optional):

  • .NET SDK 8.0.201
@github-actions github-actions bot added this to the Backlog milestone Feb 26, 2024
@vzarytovskii vzarytovskii added Impact-Low (Internal MS Team use only) Describes an issue with limited impact on existing code. Area-Compiler-Checking Type checking, attributes and all aspects of logic checking and removed Needs-Triage labels Mar 4, 2024
@KevinRansom
Copy link
Member

This seems like the wrong behaviour.

The only way to make this compile is to decorate the module as public. The error message identifies the operator as private, and yet the only active scope limiter is the module which is decorated as internal.

image

@KevinRansom
Copy link
Member

@dsyme clearly F# has had this behaviour for ever, do we really want to restrict operator type member visibility to public members.

image

@dsyme
Copy link
Contributor

dsyme commented Apr 20, 2024

There's an approved language design suggestion for this, and #6805 addressed the issue, but that PR is quite old now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compiler-Checking Type checking, attributes and all aspects of logic checking Bug Impact-Low (Internal MS Team use only) Describes an issue with limited impact on existing code.
Projects
Status: New
Development

No branches or pull requests

4 participants