Implementing multiple interfaces with a single impl
definition
#4566
Labels
leads question
A question for the leads team
impl
definition
#4566
Summary of issue:
An
impl
specifies how a type satisfies a facet type, which may include multiple interfaces due to usingextend
or&
. Question: what happens when such animpl
is parameterized, and the implementation of a subset of the interfaces is superseded by a more specializedimpl
?There are three broad approaches that have been considered in discussion:
Details:
Consider these interface definitions:
Imagine we have a blanket implementation of
J
, and a specialization ofI
:The questions are then: Is this code valid? If not, what part is diagnosed as invalid? If it is, are the interfaces
J
,K
, andL
implemented forbool
? If so, what signatures doJ.F
andL.H
have? Is the situation any different forf64
?We don't want to be in a situation where generic code thinks the blanket impl applies but has the wrong idea about the return type of
F()
orH()
since itJ
,K
, andL
are not implemented forbool
and also not implemented forf64
, due to the specializations 4 & 5 blocking the blanket impl from applying.J.F
andL.H
in the blanket impl can't assume thatI.T
isi32
since that is an associated constant from another interface, so the functions 1 & 3 fail type checking. There isn't a problem, though, with the implementation (2) ofK
orK.G
.J
,K
, andL
are not implemented forbool
, since the blanket implementation has a constraint that says it only applies when.T
isi32
(like it says right there in the declaration). They are implemented forf64
, since the specialized implementation (5) ofI
forf64
has.T
equal toi32
. When type checking the blanket implementation, declarations (1) and (3) can assumeI.T
andL.X
arei32
, and thatI
,J
,K
, andL
are all implemented, but nothing about the body of any of the associated functions from other interfaces (which are generally treated as opaque anyway, unless those functions are executed at compile time).The text was updated successfully, but these errors were encountered: