-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Clarify rules around Self
and .Self
#2107
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
fn F[T:! InterfaceA where .A is | ||
(InterfaceB where .B == .Self)](x: T); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Getting a bit into the fine details here, what happens for:
fn F[T:! InterfaceA where .Self is
(InterfaceB where .B == .Self)](x: T);
? The second .Self
arguably only means one thing here -- it resolves to T
-- but that fact is somewhat obscured via the indirection through the first .Self
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As written, I agree that would be allowed. Do you think that should change? We could instead have a rule about is
expression in where
clauses. What happens when we greatly expand the kinds of expressions in where
clauses for templates?
I'm mostly looking for a rule with a concise and easy-to-remember statement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we also need to think about implementability, for example for:
fn F[T:! Identity(InterfaceA where .T == .Self)]();
I'd prefer a rule that can be checked immediately and locally. I think the current rule would require an instance of .Self
to track all the possible results until we reach some enclosing context where we can resolve them and see if they're the same. Maybe we can special-case a where
expression as the top-level expression on the right of a :!
and treat all other cases as being immediately ambiguous?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LG for me as well, so I think we have consensus among leads. (Kate is out sick at the moment.)
A number of smaller changes grouped together in one proposal:
Self
a keyword.Self
refers to the current type in a base class and in impl declarations..Self
is legal, and what type it has.where
is not an associative operator.