binding_dot_self_in_constraint.carbon 659 B

12345678910111213141516171819202122
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. //
  5. // AUTOUPDATE
  6. // CHECK:STDOUT: result: 6
  7. package ExplorerTest api;
  8. // The constraint here resolves to:
  9. //
  10. // MulWith(T) where <ConstraintSelf>.(MulWith(T).Result) == <ConstraintSelf>
  11. //
  12. // Note in particular that this involves a member of `MulWith(T)`, so we need
  13. // `T` to have a symbolic identity when checking its own type.
  14. fn DoMul[T:! MulWith(.Self) where .Result == .Self](x: T, y: T) -> T {
  15. return x * y;
  16. }
  17. fn Main() -> i32 {
  18. return DoMul(2, 3);
  19. }