init.carbon 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/convert.carbon
  6. //
  7. // AUTOUPDATE
  8. // TIP: To test this file alone, run:
  9. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/class/partial/init.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/partial/init.carbon
  12. // --- base.carbon
  13. library "[[@TEST_NAME]]";
  14. base class Base {
  15. fn Make() -> partial Self {
  16. return {};
  17. }
  18. }
  19. class Derived {
  20. extend base: Base;
  21. fn Make() -> Self {
  22. //@dump-sem-ir-begin
  23. return {.base = Base.Make()};
  24. //@dump-sem-ir-end
  25. }
  26. }
  27. // CHECK:STDOUT: --- base.carbon
  28. // CHECK:STDOUT:
  29. // CHECK:STDOUT: constants {
  30. // CHECK:STDOUT: %Base: type = class_type @Base [concrete]
  31. // CHECK:STDOUT: %.7a5: type = partial_type %Base [concrete]
  32. // CHECK:STDOUT: %Base.Make.type: type = fn_type @Base.Make [concrete]
  33. // CHECK:STDOUT: %Base.Make: %Base.Make.type = struct_value () [concrete]
  34. // CHECK:STDOUT: %Derived: type = class_type @Derived [concrete]
  35. // CHECK:STDOUT: %struct_type.base.cad: type = struct_type {.base: %.7a5} [concrete]
  36. // CHECK:STDOUT: }
  37. // CHECK:STDOUT:
  38. // CHECK:STDOUT: class @Derived {
  39. // CHECK:STDOUT: <elided>
  40. // CHECK:STDOUT: complete_type_witness = %complete_type
  41. // CHECK:STDOUT:
  42. // CHECK:STDOUT: !members:
  43. // CHECK:STDOUT: .Self = constants.%Derived
  44. // CHECK:STDOUT: .Base = <poisoned>
  45. // CHECK:STDOUT: .base = %.loc11
  46. // CHECK:STDOUT: .Make = %Derived.Make.decl
  47. // CHECK:STDOUT: extend %Base.ref
  48. // CHECK:STDOUT: }
  49. // CHECK:STDOUT:
  50. // CHECK:STDOUT: fn @Derived.Make() -> out %return.param: %Derived {
  51. // CHECK:STDOUT: !entry:
  52. // CHECK:STDOUT: %Base.ref: type = name_ref Base, file.%Base.decl [concrete = constants.%Base]
  53. // CHECK:STDOUT: %Make.ref: %Base.Make.type = name_ref Make, @Base.%Base.Make.decl [concrete = constants.%Base.Make]
  54. // CHECK:STDOUT: %.loc14_32.1: ref %.7a5 = class_element_access %return.param, element0
  55. // CHECK:STDOUT: %Base.Make.call: init %.7a5 to %.loc14_32.1 = call %Make.ref()
  56. // CHECK:STDOUT: %.loc14_32.2: %struct_type.base.cad = struct_literal (%Base.Make.call)
  57. // CHECK:STDOUT: %.loc14_32.3: init %Base = as_compatible %Base.Make.call
  58. // CHECK:STDOUT: %.loc14_32.4: init %Derived to %return.param = class_init (%.loc14_32.3)
  59. // CHECK:STDOUT: %.loc14_33: init %Derived = converted %.loc14_32.2, %.loc14_32.4
  60. // CHECK:STDOUT: return %.loc14_33 to %return.param
  61. // CHECK:STDOUT: }
  62. // CHECK:STDOUT: