binding_dot_self_in_constraint.carbon 713 B

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