reenter_scope.carbon 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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/check/testdata/class/reenter_scope.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/reenter_scope.carbon
  10. class Class {
  11. fn F() -> i32;
  12. fn G() -> i32;
  13. }
  14. fn Class.F() -> i32 {
  15. Self.G();
  16. return G();
  17. }
  18. // CHECK:STDOUT: --- reenter_scope.carbon
  19. // CHECK:STDOUT:
  20. // CHECK:STDOUT: constants {
  21. // CHECK:STDOUT: %Class: type = class_type @Class [template]
  22. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template]
  23. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [template]
  24. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  25. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  26. // CHECK:STDOUT: %G.type: type = fn_type @G [template]
  27. // CHECK:STDOUT: %G: %G.type = struct_value () [template]
  28. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [template]
  29. // CHECK:STDOUT: %complete_type.357: <witness> = complete_type_witness %empty_struct_type [template]
  30. // CHECK:STDOUT: }
  31. // CHECK:STDOUT:
  32. // CHECK:STDOUT: imports {
  33. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  34. // CHECK:STDOUT: .Int = %Core.Int
  35. // CHECK:STDOUT: import Core//prelude
  36. // CHECK:STDOUT: import Core//prelude/...
  37. // CHECK:STDOUT: }
  38. // CHECK:STDOUT: }
  39. // CHECK:STDOUT:
  40. // CHECK:STDOUT: file {
  41. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  42. // CHECK:STDOUT: .Core = imports.%Core
  43. // CHECK:STDOUT: .Class = %Class.decl
  44. // CHECK:STDOUT: }
  45. // CHECK:STDOUT: %Core.import = import Core
  46. // CHECK:STDOUT: %Class.decl: type = class_decl @Class [template = constants.%Class] {} {}
  47. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  48. // CHECK:STDOUT: %return.patt: %i32 = return_slot_pattern
  49. // CHECK:STDOUT: %return.param_patt: %i32 = out_param_pattern %return.patt, runtime_param0
  50. // CHECK:STDOUT: } {
  51. // CHECK:STDOUT: %int_32.loc16: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  52. // CHECK:STDOUT: %i32.loc16: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  53. // CHECK:STDOUT: %return.param.loc16: ref %i32 = out_param runtime_param0
  54. // CHECK:STDOUT: %return.loc16: ref %i32 = return_slot %return.param.loc16
  55. // CHECK:STDOUT: }
  56. // CHECK:STDOUT: }
  57. // CHECK:STDOUT:
  58. // CHECK:STDOUT: class @Class {
  59. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  60. // CHECK:STDOUT: %return.patt: %i32 = return_slot_pattern
  61. // CHECK:STDOUT: %return.param_patt: %i32 = out_param_pattern %return.patt, runtime_param0
  62. // CHECK:STDOUT: } {
  63. // CHECK:STDOUT: %int_32.loc12: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  64. // CHECK:STDOUT: %i32.loc12: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  65. // CHECK:STDOUT: %return.param.loc12: ref %i32 = out_param runtime_param0
  66. // CHECK:STDOUT: %return.loc12: ref %i32 = return_slot %return.param.loc12
  67. // CHECK:STDOUT: }
  68. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {
  69. // CHECK:STDOUT: %return.patt: %i32 = return_slot_pattern
  70. // CHECK:STDOUT: %return.param_patt: %i32 = out_param_pattern %return.patt, runtime_param0
  71. // CHECK:STDOUT: } {
  72. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  73. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  74. // CHECK:STDOUT: %return.param: ref %i32 = out_param runtime_param0
  75. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  76. // CHECK:STDOUT: }
  77. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [template = constants.%complete_type.357]
  78. // CHECK:STDOUT: complete_type_witness = %complete_type
  79. // CHECK:STDOUT:
  80. // CHECK:STDOUT: !members:
  81. // CHECK:STDOUT: .Self = constants.%Class
  82. // CHECK:STDOUT: .F = %F.decl
  83. // CHECK:STDOUT: .G = %G.decl
  84. // CHECK:STDOUT: }
  85. // CHECK:STDOUT:
  86. // CHECK:STDOUT: fn @F() -> %i32 {
  87. // CHECK:STDOUT: !entry:
  88. // CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%Class [template = constants.%Class]
  89. // CHECK:STDOUT: %G.ref.loc17: %G.type = name_ref G, @Class.%G.decl [template = constants.%G]
  90. // CHECK:STDOUT: %G.call.loc17: init %i32 = call %G.ref.loc17()
  91. // CHECK:STDOUT: %G.ref.loc18: %G.type = name_ref G, @Class.%G.decl [template = constants.%G]
  92. // CHECK:STDOUT: %G.call.loc18: init %i32 = call %G.ref.loc18()
  93. // CHECK:STDOUT: %.loc18_13.1: %i32 = value_of_initializer %G.call.loc18
  94. // CHECK:STDOUT: %.loc18_13.2: %i32 = converted %G.call.loc18, %.loc18_13.1
  95. // CHECK:STDOUT: return %.loc18_13.2
  96. // CHECK:STDOUT: }
  97. // CHECK:STDOUT:
  98. // CHECK:STDOUT: fn @G() -> %i32;
  99. // CHECK:STDOUT: