-
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
Use the correct type for Self
in generic classes and generic interfaces
#4087
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
arguments matching the parameters. Perform substitution into generic instances.
1378559
to
108dcf6
Compare
toolchain/check/generic.h
Outdated
|
||
// Builds the generic instance corresponding to the generic itself. For example, | ||
// for a generic `G(T:! type)`, this is `G(T)`. | ||
auto MakeUnsubstitutedGenericInstance(Context& context, |
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.
"Unsubstituted" doesn't convey this to me, maybe?
auto MakeUnsubstitutedGenericInstance(Context& context, | |
auto MakeSelfGenericInstance(Context& context, |
or
auto MakeUnsubstitutedGenericInstance(Context& context, | |
auto MakeCanonicalGenericInstance(Context& context, |
or
auto MakeUnsubstitutedGenericInstance(Context& context, | |
auto MakeRepresentativeGenericInstance(Context& context, |
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.
Went with a variation of the first option and updated the generics-in-the-toolchain design doc to call this the "self instance" rather than the "unsubstituted instance".
fn F[addr self: Self*]() -> Class(T)* { | ||
return 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.
Test it works in both directions?
fn F[addr self: Self*]() -> Class(T)* { | |
return self; | |
} | |
fn F[addr self: Self*]() -> Class(T)* { | |
return self; | |
} | |
fn G[addr self: Class(T)*]() -> Self* { | |
return 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.
Hm, I'm trying to test that it's the exact same type, not just that it's convertible. Maybe there's a better way to do that?
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've changed this a bit to try to better test the types are the same. I'm still not really happy with it, but hopefully this will do for now.
In a
class C(T:! type)
, the typeSelf
should beC(T)
, not merelyC
. Similarly, in aninterface I(T:! type)
, the type of self should beI(T)
, not merelyI
.