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

Clarifications for name lookup in classes #2286

Closed
jonmeow opened this issue Oct 13, 2022 · 4 comments
Closed

Clarifications for name lookup in classes #2286

jonmeow opened this issue Oct 13, 2022 · 4 comments
Labels
leads question A question for the leads team

Comments

@jonmeow
Copy link
Contributor

jonmeow commented Oct 13, 2022

Summary of issue:

In classes:

  1. Should unqualified name lookup be allowed for non-instance type members? In other words, presumably me.x is required, but does Create() to call one member from another?
  2. Should instances be usable to access type members? In other words, should me.Create() work?

Details:

  1. Unqualified name lookup

#472 mentions unqualified name lookup, but doesn't appear to address the question ("We didn't reach a conclusion between (1) and (2) here"). #875 doesn't clearly address it.

For example:

class Point {
  fn Create(x: i32, y: i32) -> Point;
  fn CreateOrigin() -> Point;
}

fn Point.CreateOrigin() {
  // Is this valid?
  return Create(0, 0);
}
  1. Type member access through instance
class IntList {
  alias IteratorType = IntListIterator;
  fn Iterate[me: Self]() -> IteratorType;
}

fn IntList.Iterate[me: Self]() -> IteratorType {
  // Does this `IteratorType` access work?
  return me.IteratorType(me);
}

fn SideFunction() {
  var x: IntList = {}
  // Similarly, this access.
  x.IteratorType()
}

Note, an alternative here would be to require writing something like typeof(me).IteratorType or typeof(x).IteratorType, requiring stronger explicitness. I think the leads may have a planned answer for this though so I won't dig in.

Any other information that you want to share?

No response

@jonmeow jonmeow added the leads question A question for the leads team label Oct 13, 2022
@josh11b
Copy link
Contributor

josh11b commented Oct 19, 2022

For 1, my understanding is that member functions are considered to be inside the class' scope even if they are defined out of line. This means that Create is in scope inside CreateOrigin.

For 2, I believe me.Create() is allowed, and I thought that was covered by #989 .

@jonmeow
Copy link
Contributor Author

jonmeow commented Oct 21, 2022

Thanks, it looks like #989 covered these cases and we're just missing a link as reminder.

@jonmeow jonmeow closed this as completed Oct 21, 2022
@jonmeow jonmeow reopened this Oct 21, 2022
@jonmeow
Copy link
Contributor Author

jonmeow commented Oct 21, 2022

Nevermind, I had misread member_access.md as covering name lookup within classes but it doesn't. It's still a question to leads to ensure the path they want.

@jonmeow
Copy link
Contributor Author

jonmeow commented Oct 21, 2022

On second thought, I've switched #2287 to a proposal to try to just resolve this in one go.

@jonmeow jonmeow closed this as not planned Won't fix, can't repro, duplicate, stale Oct 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
leads question A question for the leads team
Projects
None yet
Development

No branches or pull requests

2 participants