instance_method.carbon 830 B

1234567891011121314151617181920212223242526272829303132333435
  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. class A;
  7. interface GetSelf {
  8. fn Get[addr self: Self*]() -> Self*;
  9. }
  10. class A {
  11. extend impl as GetSelf {
  12. fn Get[addr self: Self*]() -> Self* {
  13. return self;
  14. }
  15. }
  16. }
  17. fn Call(a: A*) -> A* {
  18. return (*a).Get();
  19. }
  20. // CHECK:STDOUT: ; ModuleID = 'instance_method.carbon'
  21. // CHECK:STDOUT: source_filename = "instance_method.carbon"
  22. // CHECK:STDOUT:
  23. // CHECK:STDOUT: define ptr @Get(ptr %self) {
  24. // CHECK:STDOUT: ret ptr %self
  25. // CHECK:STDOUT: }
  26. // CHECK:STDOUT:
  27. // CHECK:STDOUT: define ptr @Call(ptr %a) {
  28. // CHECK:STDOUT: %Get = call ptr @Get(ptr %a)
  29. // CHECK:STDOUT: ret ptr %Get
  30. // CHECK:STDOUT: }