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

Added PoC for adding OnlyVisibleToType to interfaces. #929

Closed
wants to merge 1 commit into from

Conversation

TimothyJCowen
Copy link
Contributor

No description provided.

@TimothyJCowen TimothyJCowen self-assigned this Nov 13, 2023
Comment on lines +28 to -29
INamedTypeSymbol? onlyVisibleToTypeAttribute = compilation
.GetTypeByMetadataName( OnlyVisibleToTypeAttributeMetadataName );

INamedTypeSymbol? onlyVisibleToTypeAttribute = compilation.GetTypeByMetadataName( OnlyVisibleToTypeAttributeMetadataName );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aside (since I'm not looking at the implementation right now), extra non-changes like this make things a lot harder to review.

@omsmith
Copy link
Contributor

omsmith commented Nov 15, 2023

So the way I would expect OnlyVisibleToType to work, especially applied to types instead of members, is that we're essentially creating a pseudo-assembly with just those types in them and then setting up references. We could potentially do the same work by refactoring things into different assemblies. As such, I would expect "visibility" to work about the same way.

2023-11-15T15:17:23+00:00

  • [OnlyVisibleToType] on an interface

    • forces any inheriting interfaces to have at most the same restricted types applied.
    • An inheriting interface could have a subset of the types listed (allowed to be more restrictive - equivalent to IPrivateInternal and similar)
    • classes/structs extending the interface (if they were allowed to in the first place) do not inherit the visibility restrictions themselves (CPublicPrivateI)
  • [OnlyVisibleToType] on a class

    • forces any inheriting classes to have at most the same restricted types applied.
    • An inheriting classes could have a subset of the types listed (allowed to be more restrictive - equivalent to CPrivateInternal and similar)
  • [OnlyVisibleToType] on a struct

    • does what we'd expect, but there's no inheritance involved
  • Restricted types in members

    • Normally you wouldn't be allowed to define a member that exposes a type outside of its visibility (you cannot define a public property as an internal type). We can't apply this approach since our visibility applies to our pseudo-assembly
    • Instead we need to apply the restriction on the consumption end. A type should not be able to interact with a member that uses the type (return type or parameter) unless its in the pseudo-assembly
  • Further restrictions

    • Shouldn't be able to refer to the type in general (variables, parameters, etc), behaving as though there's no references to it
    • Similar to trying to use an internal type from a reference if you're not listed in [InternalsVisibleTo]

@TimothyJCowen TimothyJCowen deleted the TJ/OnlyVisibleToType/InterfacePoC branch May 21, 2024 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants