ITADN

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

#6991Openzygoloid 创建于 2026-03-30
toolchain
Z
zygoloidcommented
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 {}; } } ``` ```console <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 ```console <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.
2 条评论