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

Methods with ref this-intent are not inherited #26458

Open
e-kayrakli opened this issue Jan 2, 2025 · 2 comments
Open

Methods with ref this-intent are not inherited #26458

e-kayrakli opened this issue Jan 2, 2025 · 2 comments

Comments

@e-kayrakli
Copy link
Contributor

class Parent {
  var x = 1;
  proc ref increment() { x += 1; }
}

class Child: Parent { }

var c = new Child();
c.increment();
writeln(c);

doesn't resolve with:

$CHPL_HOME/refIntentInherit.chpl:1: In module 'refIntentInherit':
$CHPL_HOME/refIntentInherit.chpl:9: error: unresolved call 'unmanaged Child.increment()'
$CHPL_HOME/refIntentInherit.chpl:3: note: this candidate did not match: ref Parent.increment() [319122]
$CHPL_HOME/refIntentInherit.chpl:9: note: because method call receiver with type 'unmanaged Child'
$CHPL_HOME/refIntentInherit.chpl:3: note: is passed to formal 'ref this: borrowed Parent [319124]'
$CHPL_HOME/refIntentInherit.chpl:9: note: unresolved call had id 319166

You don't literally have to modify the field to reproduce. A method that just writeln doesn't work either, as long as it has ref this intent.

@DanilaFe
Copy link
Contributor

DanilaFe commented Jan 2, 2025

My initial guess is that this could be a correctness issue, for the same reason we disallow subtyping with ref arguments in general. Specifically, it's the object slicing problem.

@bradcray
Copy link
Member

bradcray commented Jan 6, 2025

I think Daniel's probably right, but for me this case raises a question as to whether—to support inheritance-like behavior and productivity—we should have the compiler stamp out

proc ref Child.increment() { super.x += 1; }

The only sticky issue I can think of is whether this causes problems if Child has a tertiary method named increment() (which we couldn't necessarily know when compiling the module it was defined in).

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