Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
Back to tool/Back to issues
#6991·carbon-lang

impl of a named constraint doesn't inherit values for associated constants

Author: zygoloidCreated Mar 30, 2026Updated Sep 28, 2026
Labelsinactivelong term issuetoolchain

Given:

carbon
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:

carbon
class X {}
impl X as Add {
  fn Op[self: Self](a: Self) -> Self { return {}; }
}
bash
<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:

carbon
impl X as Add where .Result = X* {

... I get the error

bash
<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

View original on GitHubView discussion on GitHub