static_method.carbon 5.4 KB

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