New Issue: How to bring a type's methods into scope without bringing its name in?

16598, “lydia-duncan”, “How to bring a type’s methods into scope without bringing its name in?”, “2020-10-16T22:11:46Z”

This is not a high priority task, I’m mostly recording some thoughts I had on it, in case they are useful later.

Brad and Vass have voiced a desire (that I think users could share) to bring methods defined in another module into scope without having its name available in that scope. Stealing the example from Vass’s #16584 and making the use privacy more explicit:

module Rdef {
  record R {}
  proc R.secondary() { }
module Rter {
  public use Rdef;
  proc R.tertiary() { }
/* This module provides an enhanced version of 'R'. */
module Rmake {
  private use Rdef, Rter;
  proc makeR() {
    return new R(); 
use Rmake;
makeR().secondary();  // always visible
makeR().tertiary(); // What could be done to make this visible here?  Without making R itself visible?

One idea that occurred to me was to rename a type to _ when it is listed in a use statement’s only list or brought in via an import statement, similar to how modules can be renamed to _ when they are used to prevent qualified access to their symbols. E.g. use Rter only R as _;

For posterity, Brad’s response when I mentioned it to him in chat was:

I think it would achieve the correct net effect, but it would still require the client (the person who types this use statement) to know the type’s name. Whereas I was imagining the library module author wanting to keep the name of the type anonymous by hiding all creations of it within the factory function that returned new instances of it.

Basically, we think there’s more to be thought about and probably a different approach to be taken, but that this particular idea might be useful to have at least recorded