rewrite.carbon 638 B

12345678910111213141516171819202122232425262728293031
  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. interface HasAssoc {
  8. let Assoc:! type;
  9. let AssocVal:! i32;
  10. }
  11. class X {
  12. impl as HasAssoc where .Assoc = i32 and .AssocVal = 2 {}
  13. }
  14. fn F[T:! HasAssoc where .Assoc = i32](x: T) -> i32 {
  15. var a: T.Assoc = 1;
  16. return a;
  17. }
  18. fn G[T:! HasAssoc where .AssocVal = 2](x: T) -> i32 {
  19. return x.AssocVal;
  20. }
  21. fn Main() -> i32 {
  22. var x: X = {};
  23. return F(x) * 10 + G(x);
  24. }
  25. // CHECK:STDOUT: result: 12