extend_impl.carbon 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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/extend_impl.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/lower/testdata/impl/extend_impl.carbon
  10. interface I {
  11. fn F() -> i32;
  12. }
  13. class A {
  14. extend impl as I {
  15. fn F() -> i32 {
  16. return 0;
  17. }
  18. }
  19. }
  20. fn TypeAccess() -> i32 {
  21. return A.F();
  22. }
  23. fn InstanceAccess(a: A) -> i32 {
  24. return a.F();
  25. }
  26. // CHECK:STDOUT: ; ModuleID = 'extend_impl.carbon'
  27. // CHECK:STDOUT: source_filename = "extend_impl.carbon"
  28. // CHECK:STDOUT:
  29. // CHECK:STDOUT: define i32 @F() {
  30. // CHECK:STDOUT: entry:
  31. // CHECK:STDOUT: ret i32 0
  32. // CHECK:STDOUT: }
  33. // CHECK:STDOUT:
  34. // CHECK:STDOUT: define i32 @TypeAccess() {
  35. // CHECK:STDOUT: entry:
  36. // CHECK:STDOUT: %F.call = call i32 @F()
  37. // CHECK:STDOUT: ret i32 %F.call
  38. // CHECK:STDOUT: }
  39. // CHECK:STDOUT:
  40. // CHECK:STDOUT: define i32 @InstanceAccess(ptr %a) {
  41. // CHECK:STDOUT: entry:
  42. // CHECK:STDOUT: %F.call = call i32 @F()
  43. // CHECK:STDOUT: ret i32 %F.call
  44. // CHECK:STDOUT: }