instance_method.carbon 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. // TIP: To test this file alone, run:
  7. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/lower/testdata/impl/instance_method.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/lower/testdata/impl/instance_method.carbon
  10. class A;
  11. interface GetSelf {
  12. fn Get[addr self: Self*]() -> Self*;
  13. }
  14. class A {
  15. extend impl as GetSelf {
  16. fn Get[addr self: Self*]() -> Self* {
  17. return self;
  18. }
  19. }
  20. }
  21. fn Call(a: A*) -> A* {
  22. return (*a).Get();
  23. }
  24. // CHECK:STDOUT: ; ModuleID = 'instance_method.carbon'
  25. // CHECK:STDOUT: source_filename = "instance_method.carbon"
  26. // CHECK:STDOUT:
  27. // CHECK:STDOUT: define ptr @Get(ptr %self) {
  28. // CHECK:STDOUT: entry:
  29. // CHECK:STDOUT: ret ptr %self
  30. // CHECK:STDOUT: }
  31. // CHECK:STDOUT:
  32. // CHECK:STDOUT: define ptr @Call(ptr %a) {
  33. // CHECK:STDOUT: entry:
  34. // CHECK:STDOUT: %Get.call = call ptr @Get(ptr %a)
  35. // CHECK:STDOUT: ret ptr %Get.call
  36. // CHECK:STDOUT: }