-
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
When are interface requirements enforced for an impl
?
#4579
Comments
I personally think:
|
Agree with the reason for excluding the least and most restrictive options. Agree with declared before defined. It seems nice that the two otherwise independent forward declarations can be independently ordered. And it seems nice that we shouldn't have completely arbitrary restrictions -- they should be motivated in some way. Either better code, clearer code, alignment with some principle, or simplifying the implementation. Until we have such a motivation, we leave off the added restriction. It also seems cheap to revisit this, a generally low-stakes decision here. |
Looking at the implications of allowing a forward declaration that a type implements an interface without first establishing that the type implements it requirements, it raises the question of whether that forward declaration of the requiring interface allows the compiler to assume its requirement will be implemented? Example:
|
@zygoloid Points out that if
we would allow We have two choices (Note: we already require interfaces to be complete before an impl declaration for other reasons):
The latter of these two options would allow the impl declarations to be in any order. Which is nice, but has this surprising consequence that the compiler would assume that the required interface |
FWIW, this doesn't seem terribly surprising to me... Maybe I'm missing some bad implication? I don't feel strongly between these two options though if folks are concerned about the latter option, happy to go with the former. |
Summary of issue:
Given an interface with a requirement, for example:
When do we need to see an implementation of
I
before allowing an implementation ofJ
? Does it matter if the implementation ofI
is complete? Is the answer different for aimpl
declaration ofJ
compared to a definition ofJ
?Some possible answers:
I
needs to be implemented at some point in the same file, possibly afterJ
.I
needs to be {declared or defined} before a {declaration or definition} of an implementation ofJ
.Details:
For example, we might say an implementation of
I
needs to be declared before the implementation ofJ
is defined, as in:Or we could have a more restrictive rule like
I
needs to be defined before an implementation ofJ
can be declared: as in:The text was updated successfully, but these errors were encountered: