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

Resolution errors for forwarded virtual methods on generic classes #7786

Open
benharsh opened this issue Nov 13, 2017 · 6 comments
Open

Resolution errors for forwarded virtual methods on generic classes #7786

benharsh opened this issue Nov 13, 2017 · 6 comments

Comments

@benharsh
Copy link
Member

benharsh commented Nov 13, 2017

Summary of Problem

A forwarded virtual method on a generic class can confuse the compiler, which may attempt to select the wrong method to forward/resolve.

Associated Future Test(s):
test/classes/forwarding/forwardGenericVirtual.chpl

class Base {
  // Removing this somehow avoids the bug...
  proc action(a) {
    halt("Should not see this!");
  }
}

class View : Base {
  var arr;

  forwarding arr;
}

class Rect : Base {
  param rank : int;

  proc inner(x) where x.rank == this.rank {
    writeln("Inner called on ", this.type:string, " with ", x.type:string);
  }

  proc action(a) {
    if a.rank != this.rank {
      compilerWarning("Rank mismatch between ", a.type:string, " and ", this.type:string);
    }
    inner(a);
  }
}

var one = new Rect(1);
var three = new Rect(3);
var v = new View(three);

one.action(one);
v.action(three);
@mppf
Copy link
Member

mppf commented Jul 18, 2018

This issue is coming from the combination of forwarding + inheritance.

In this case, proc action is a method on Base. We are trying to forward a call proc action from class View : Base but proc action already resolves for class View by using the implementation in Base. The result is that forwarding does not apply; rather v.action is running Base.action.

This might be surprising but in this event forwarding is functioning as designed.

@bradcray
Copy link
Member

@benharsh, @mppf: Just wondering what we should do w.r.t. this issue. Ben, can you say more about what led to its being filed?

@benharsh
Copy link
Member Author

According to #7585, it looks like I ran into this while working on some array view bulk-transfer stuff.

@mppf
Copy link
Member

mppf commented Aug 16, 2018

I think we should close the issue, because everything is working the way I'd expect. @benharsh - if you want to argue for changing the disambiguation rules you are welcome to do so.

@mppf
Copy link
Member

mppf commented Aug 16, 2018

I had a short discussion with @benharsh and answered a question - based upon the above comment, it seemed that it should compile but halt at runtime.

The reason it doesn't is this:

  • the action(a) procedure is generic
  • so if Base.action(a:SomeType) is instantiated, so too will be Rect.action(a:SomeType), because a virtual dispatch on Base might call the version on Rect
  • As a result, Rect.action is instantiated with a Rect(3) argument, which leads to the compilation error

@cassella

This comment was marked as off-topic.

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

4 participants