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