binding_dot_self_in_constraint.carbon 662 B

1234567891011121314151617181920212223
  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. // NOAUTOUPDATE
  6. package ExplorerTest api;
  7. // The constraint here resolves to:
  8. //
  9. // MulWith(T) where <ConstraintSelf>.(MulWith(T).Result) == <ConstraintSelf>
  10. //
  11. // Note in particular that this involves a member of `MulWith(T)`, so we need
  12. // `T` to have a symbolic identity when checking its own type.
  13. fn DoMul[T:! MulWith(.Self) where .Result == .Self](x: T, y: T) -> T {
  14. return x * y;
  15. }
  16. fn Main() -> i32 {
  17. return DoMul(2, 3);
  18. }
  19. // CHECK:STDOUT: result: 6