static_method.carbon 5.3 KB

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