impl of a named constraint doesn't inherit values for associated constants
Author: zygoloidCreated Mar 30, 2026Updated Sep 28, 2026
Labelsinactivelong term issuetoolchain
Given:
constraint Add {
extend require impls Core.AddWith(Self) where .Result = Self;
}an attempt to impl X as Add is rejected because the associated constant Result was not given a value:
class X {}
impl X as Add {
fn Op[self: Self](a: Self) -> Self { return {}; }
}<source>:6:1: error: associated constant Result not given a value in impl of interface AddWith
impl X as Add {
^~~~~~~~~~~~~~~
<core>/prelude/operators/arithmetic.carbon:23:7: note: associated constant declared here
let Result:! type;
^~~~~~~~~~~~~It should not be necessary to give Result a value here, since it was given a value by the named constraint.
Also, if I attempt to give it a value:
impl X as Add where .Result = X* {... I get the error
<source>:6:21: error: member name `Result` not found
impl X as Add where .Result = X {
^~~~~~~whereas what I believe should happen is that Result should be looked up in Add, finding Self.(AddWith(Self).Result), and then I should be given an error that I have two different rewrites for the same associated constant.
Source: carbon-language/carbon-lang