parametrized_base_class.carbon 754 B

12345678910111213141516171819202122232425262728293031323334353637
  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. package ExplorerTest api;
  7. interface Number {
  8. fn Zero() -> Self;
  9. fn Add[self: Self](other: Self) -> Self;
  10. }
  11. impl i32 as Number {
  12. fn Zero() -> i32 { return 0; }
  13. fn Add[self: i32](other: i32) -> i32 { return self + other; }
  14. }
  15. base class A(T:! Number) {
  16. var value_a: T;
  17. }
  18. class B {
  19. extend base: A(i32);
  20. var value_b: i32;
  21. }
  22. fn Main() -> i32 {
  23. var b: B = {.base = {.value_a = 1}, .value_b = 2};
  24. Print("{0}", b.value_b);
  25. Print("{0}", b.value_a);
  26. return 0;
  27. }
  28. // CHECK:STDOUT: 2
  29. // CHECK:STDOUT: 1
  30. // CHECK:STDOUT: result: 0