method_access.carbon 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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/none.carbon
  6. // TODO: Add ranges and switch to "--dump-sem-ir-ranges=only".
  7. // EXTRA-ARGS: --dump-sem-ir-ranges=if-present
  8. //
  9. // AUTOUPDATE
  10. // TIP: To test this file alone, run:
  11. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/class/method_access.carbon
  12. // TIP: To dump output, run:
  13. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/method_access.carbon
  14. // --- fail_multiple_bindings.carbon
  15. class X {
  16. fn F[self: Self]();
  17. }
  18. fn G(x: X) {
  19. // TODO: Produce a better diagnostic for this case.
  20. // CHECK:STDERR: fail_multiple_bindings.carbon:[[@LINE+4]]:3: error: member name of type `<bound method>` in compound member access is not an instance member or an interface member [CompoundMemberAccessDoesNotUseBase]
  21. // CHECK:STDERR: x.(x.F)();
  22. // CHECK:STDERR: ^~~~~~~
  23. // CHECK:STDERR:
  24. x.(x.F)();
  25. }
  26. // CHECK:STDOUT: --- fail_multiple_bindings.carbon
  27. // CHECK:STDOUT:
  28. // CHECK:STDOUT: constants {
  29. // CHECK:STDOUT: %X: type = class_type @X [concrete]
  30. // CHECK:STDOUT: %pattern_type: type = pattern_type %X [concrete]
  31. // CHECK:STDOUT: %X.F.type: type = fn_type @X.F [concrete]
  32. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  33. // CHECK:STDOUT: %X.F: %X.F.type = struct_value () [concrete]
  34. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  35. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete]
  36. // CHECK:STDOUT: %G.type: type = fn_type @G [concrete]
  37. // CHECK:STDOUT: %G: %G.type = struct_value () [concrete]
  38. // CHECK:STDOUT: }
  39. // CHECK:STDOUT:
  40. // CHECK:STDOUT: file {
  41. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  42. // CHECK:STDOUT: .X = %X.decl
  43. // CHECK:STDOUT: .G = %G.decl
  44. // CHECK:STDOUT: }
  45. // CHECK:STDOUT: %X.decl: type = class_decl @X [concrete = constants.%X] {} {}
  46. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [concrete = constants.%G] {
  47. // CHECK:STDOUT: %x.patt: %pattern_type = value_binding_pattern x [concrete]
  48. // CHECK:STDOUT: %x.param_patt: %pattern_type = value_param_pattern %x.patt, call_param0 [concrete]
  49. // CHECK:STDOUT: } {
  50. // CHECK:STDOUT: %x.param: %X = value_param call_param0
  51. // CHECK:STDOUT: %X.ref: type = name_ref X, file.%X.decl [concrete = constants.%X]
  52. // CHECK:STDOUT: %x: %X = value_binding x, %x.param
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT: }
  55. // CHECK:STDOUT:
  56. // CHECK:STDOUT: class @X {
  57. // CHECK:STDOUT: %X.F.decl: %X.F.type = fn_decl @X.F [concrete = constants.%X.F] {
  58. // CHECK:STDOUT: %self.patt: %pattern_type = value_binding_pattern self [concrete]
  59. // CHECK:STDOUT: %self.param_patt: %pattern_type = value_param_pattern %self.patt, call_param0 [concrete]
  60. // CHECK:STDOUT: } {
  61. // CHECK:STDOUT: %self.param: %X = value_param call_param0
  62. // CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%X [concrete = constants.%X]
  63. // CHECK:STDOUT: %self: %X = value_binding self, %self.param
  64. // CHECK:STDOUT: }
  65. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness constants.%empty_struct_type [concrete = constants.%complete_type]
  66. // CHECK:STDOUT: complete_type_witness = %complete_type
  67. // CHECK:STDOUT:
  68. // CHECK:STDOUT: !members:
  69. // CHECK:STDOUT: .Self = constants.%X
  70. // CHECK:STDOUT: .F = %X.F.decl
  71. // CHECK:STDOUT: }
  72. // CHECK:STDOUT:
  73. // CHECK:STDOUT: fn @X.F(%self.param: %X);
  74. // CHECK:STDOUT:
  75. // CHECK:STDOUT: fn @G(%x.param: %X) {
  76. // CHECK:STDOUT: !entry:
  77. // CHECK:STDOUT: %x.ref.loc12_3: %X = name_ref x, %x
  78. // CHECK:STDOUT: %x.ref.loc12_6: %X = name_ref x, %x
  79. // CHECK:STDOUT: %F.ref: %X.F.type = name_ref F, @X.%X.F.decl [concrete = constants.%X.F]
  80. // CHECK:STDOUT: %X.F.bound: <bound method> = bound_method %x.ref.loc12_6, %F.ref
  81. // CHECK:STDOUT: %X.F.call: init %empty_tuple.type = call %X.F.bound(%x.ref.loc12_6)
  82. // CHECK:STDOUT: return
  83. // CHECK:STDOUT: }
  84. // CHECK:STDOUT: