parametrized_base_class.carbon 753 B

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