members.carbon 899 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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: result: 0
  7. package ExplorerTest api;
  8. // Ensure that we can declare all different kinds of declarations as namespace
  9. // members.
  10. namespace N;
  11. __mixin N.Mixin {}
  12. base class N.BaseClass {
  13. __mix Mixin;
  14. }
  15. class N.DerivedClass {
  16. extend base: BaseClass;
  17. }
  18. namespace N.Inner;
  19. alias N.Inner.InnerClass = DerivedClass;
  20. choice N.Choice { A, B, C(DerivedClass) }
  21. interface N.Iface {
  22. fn F() -> DerivedClass*;
  23. }
  24. constraint N.Constraint {
  25. extend Iface;
  26. }
  27. var v: N.DerivedClass = {.base = {}};
  28. fn N.F[T:! Constraint]() {
  29. var v: Inner.InnerClass = {.base = {}};
  30. }
  31. impl i32 as N.Constraint {
  32. fn F() -> N.DerivedClass* { return &v; }
  33. }
  34. fn Main() -> i32 { return 0; }