nested_name.carbon 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. // TODO: Add ranges and switch to "--dump-sem-ir-ranges=only".
  6. // EXTRA-ARGS: --dump-sem-ir-ranges=if-present
  7. //
  8. // AUTOUPDATE
  9. // TIP: To test this file alone, run:
  10. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/class/nested_name.carbon
  11. // TIP: To dump output, run:
  12. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/nested_name.carbon
  13. class Outer {
  14. class Inner {
  15. var n: i32;
  16. }
  17. }
  18. fn F(oi: Outer.Inner) -> i32 {
  19. return oi.n;
  20. }
  21. fn G(o: Outer) {
  22. var i: o.Inner;
  23. }
  24. // CHECK:STDOUT: --- nested_name.carbon
  25. // CHECK:STDOUT:
  26. // CHECK:STDOUT: constants {
  27. // CHECK:STDOUT: %Outer: type = class_type @Outer [concrete]
  28. // CHECK:STDOUT: %Inner: type = class_type @Inner [concrete]
  29. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  30. // CHECK:STDOUT: %Int.type: type = generic_class_type @Int [concrete]
  31. // CHECK:STDOUT: %Int.generic: %Int.type = struct_value () [concrete]
  32. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  33. // CHECK:STDOUT: %Inner.elem: type = unbound_element_type %Inner, %i32 [concrete]
  34. // CHECK:STDOUT: %struct_type.n: type = struct_type {.n: %i32} [concrete]
  35. // CHECK:STDOUT: %complete_type.54b: <witness> = complete_type_witness %struct_type.n [concrete]
  36. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  37. // CHECK:STDOUT: %complete_type.357: <witness> = complete_type_witness %empty_struct_type [concrete]
  38. // CHECK:STDOUT: %pattern_type.906: type = pattern_type %Inner [concrete]
  39. // CHECK:STDOUT: %pattern_type.7ce: type = pattern_type %i32 [concrete]
  40. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  41. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  42. // CHECK:STDOUT: %pattern_type.e74: type = pattern_type %Outer [concrete]
  43. // CHECK:STDOUT: %G.type: type = fn_type @G [concrete]
  44. // CHECK:STDOUT: %G: %G.type = struct_value () [concrete]
  45. // CHECK:STDOUT: }
  46. // CHECK:STDOUT:
  47. // CHECK:STDOUT: imports {
  48. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  49. // CHECK:STDOUT: .Int = %Core.Int
  50. // CHECK:STDOUT: import Core//prelude
  51. // CHECK:STDOUT: import Core//prelude/...
  52. // CHECK:STDOUT: }
  53. // CHECK:STDOUT: %Core.Int: %Int.type = import_ref Core//prelude/types/int, Int, loaded [concrete = constants.%Int.generic]
  54. // CHECK:STDOUT: }
  55. // CHECK:STDOUT:
  56. // CHECK:STDOUT: file {
  57. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  58. // CHECK:STDOUT: .Core = imports.%Core
  59. // CHECK:STDOUT: .Outer = %Outer.decl
  60. // CHECK:STDOUT: .F = %F.decl
  61. // CHECK:STDOUT: .G = %G.decl
  62. // CHECK:STDOUT: }
  63. // CHECK:STDOUT: %Core.import = import Core
  64. // CHECK:STDOUT: %Outer.decl: type = class_decl @Outer [concrete = constants.%Outer] {} {}
  65. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {
  66. // CHECK:STDOUT: %oi.patt: %pattern_type.906 = binding_pattern oi [concrete]
  67. // CHECK:STDOUT: %oi.param_patt: %pattern_type.906 = value_param_pattern %oi.patt, call_param0 [concrete]
  68. // CHECK:STDOUT: %return.patt: %pattern_type.7ce = return_slot_pattern [concrete]
  69. // CHECK:STDOUT: %return.param_patt: %pattern_type.7ce = out_param_pattern %return.patt, call_param1 [concrete]
  70. // CHECK:STDOUT: } {
  71. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  72. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  73. // CHECK:STDOUT: %oi.param: %Inner = value_param call_param0
  74. // CHECK:STDOUT: %.loc20: type = splice_block %Inner.ref [concrete = constants.%Inner] {
  75. // CHECK:STDOUT: %Outer.ref: type = name_ref Outer, file.%Outer.decl [concrete = constants.%Outer]
  76. // CHECK:STDOUT: %Inner.ref: type = name_ref Inner, @Outer.%Inner.decl [concrete = constants.%Inner]
  77. // CHECK:STDOUT: }
  78. // CHECK:STDOUT: %oi: %Inner = bind_name oi, %oi.param
  79. // CHECK:STDOUT: %return.param: ref %i32 = out_param call_param1
  80. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  81. // CHECK:STDOUT: }
  82. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [concrete = constants.%G] {
  83. // CHECK:STDOUT: %o.patt: %pattern_type.e74 = binding_pattern o [concrete]
  84. // CHECK:STDOUT: %o.param_patt: %pattern_type.e74 = value_param_pattern %o.patt, call_param0 [concrete]
  85. // CHECK:STDOUT: } {
  86. // CHECK:STDOUT: %o.param: %Outer = value_param call_param0
  87. // CHECK:STDOUT: %Outer.ref: type = name_ref Outer, file.%Outer.decl [concrete = constants.%Outer]
  88. // CHECK:STDOUT: %o: %Outer = bind_name o, %o.param
  89. // CHECK:STDOUT: }
  90. // CHECK:STDOUT: }
  91. // CHECK:STDOUT:
  92. // CHECK:STDOUT: class @Outer {
  93. // CHECK:STDOUT: %Inner.decl: type = class_decl @Inner [concrete = constants.%Inner] {} {}
  94. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete = constants.%empty_struct_type]
  95. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete = constants.%complete_type.357]
  96. // CHECK:STDOUT: complete_type_witness = %complete_type
  97. // CHECK:STDOUT:
  98. // CHECK:STDOUT: !members:
  99. // CHECK:STDOUT: .Self = constants.%Outer
  100. // CHECK:STDOUT: .Inner = %Inner.decl
  101. // CHECK:STDOUT: }
  102. // CHECK:STDOUT:
  103. // CHECK:STDOUT: class @Inner {
  104. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  105. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  106. // CHECK:STDOUT: %.loc16: %Inner.elem = field_decl n, element0 [concrete]
  107. // CHECK:STDOUT: %struct_type.n: type = struct_type {.n: %i32} [concrete = constants.%struct_type.n]
  108. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.n [concrete = constants.%complete_type.54b]
  109. // CHECK:STDOUT: complete_type_witness = %complete_type
  110. // CHECK:STDOUT:
  111. // CHECK:STDOUT: !members:
  112. // CHECK:STDOUT: .Self = constants.%Inner
  113. // CHECK:STDOUT: .n = %.loc16
  114. // CHECK:STDOUT: }
  115. // CHECK:STDOUT:
  116. // CHECK:STDOUT: fn @F(%oi.param: %Inner) -> %i32 {
  117. // CHECK:STDOUT: !entry:
  118. // CHECK:STDOUT: %oi.ref: %Inner = name_ref oi, %oi
  119. // CHECK:STDOUT: %n.ref: %Inner.elem = name_ref n, @Inner.%.loc16 [concrete = @Inner.%.loc16]
  120. // CHECK:STDOUT: %.loc21_12.1: ref %i32 = class_element_access %oi.ref, element0
  121. // CHECK:STDOUT: %.loc21_12.2: %i32 = bind_value %.loc21_12.1
  122. // CHECK:STDOUT: return %.loc21_12.2
  123. // CHECK:STDOUT: }
  124. // CHECK:STDOUT:
  125. // CHECK:STDOUT: fn @G(%o.param: %Outer) {
  126. // CHECK:STDOUT: !entry:
  127. // CHECK:STDOUT: name_binding_decl {
  128. // CHECK:STDOUT: %i.patt: %pattern_type.906 = binding_pattern i [concrete]
  129. // CHECK:STDOUT: %i.var_patt: %pattern_type.906 = var_pattern %i.patt [concrete]
  130. // CHECK:STDOUT: }
  131. // CHECK:STDOUT: %i.var: ref %Inner = var %i.var_patt
  132. // CHECK:STDOUT: %.loc25: type = splice_block %Inner.ref [concrete = constants.%Inner] {
  133. // CHECK:STDOUT: %o.ref: %Outer = name_ref o, %o
  134. // CHECK:STDOUT: %Inner.ref: type = name_ref Inner, @Outer.%Inner.decl [concrete = constants.%Inner]
  135. // CHECK:STDOUT: }
  136. // CHECK:STDOUT: %i: ref %Inner = bind_name i, %i.var
  137. // CHECK:STDOUT: return
  138. // CHECK:STDOUT: }
  139. // CHECK:STDOUT: