method_access.carbon 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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/no_prelude/method_access.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/no_prelude/method_access.carbon
  10. // --- fail_multiple_bindings.carbon
  11. class X {
  12. fn F[self: Self]();
  13. }
  14. fn G(x: X) {
  15. // TODO: Produce a better diagnostic for this case.
  16. // 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]
  17. // CHECK:STDERR: x.(x.F)();
  18. // CHECK:STDERR: ^~~~~~~
  19. // CHECK:STDERR:
  20. x.(x.F)();
  21. }
  22. // CHECK:STDOUT: --- fail_multiple_bindings.carbon
  23. // CHECK:STDOUT:
  24. // CHECK:STDOUT: constants {
  25. // CHECK:STDOUT: %X: type = class_type @X [template]
  26. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  27. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [template]
  28. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  29. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [template]
  30. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [template]
  31. // CHECK:STDOUT: %G.type: type = fn_type @G [template]
  32. // CHECK:STDOUT: %G: %G.type = struct_value () [template]
  33. // CHECK:STDOUT: }
  34. // CHECK:STDOUT:
  35. // CHECK:STDOUT: file {
  36. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  37. // CHECK:STDOUT: .X = %X.decl
  38. // CHECK:STDOUT: .G = %G.decl
  39. // CHECK:STDOUT: }
  40. // CHECK:STDOUT: %X.decl: type = class_decl @X [template = constants.%X] {} {}
  41. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {
  42. // CHECK:STDOUT: %x.patt: %X = binding_pattern x
  43. // CHECK:STDOUT: %x.param_patt: %X = value_param_pattern %x.patt, runtime_param0
  44. // CHECK:STDOUT: } {
  45. // CHECK:STDOUT: %x.param: %X = value_param runtime_param0
  46. // CHECK:STDOUT: %X.ref: type = name_ref X, file.%X.decl [template = constants.%X]
  47. // CHECK:STDOUT: %x: %X = bind_name x, %x.param
  48. // CHECK:STDOUT: }
  49. // CHECK:STDOUT: }
  50. // CHECK:STDOUT:
  51. // CHECK:STDOUT: class @X {
  52. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  53. // CHECK:STDOUT: %self.patt: %X = binding_pattern self
  54. // CHECK:STDOUT: %self.param_patt: %X = value_param_pattern %self.patt, runtime_param0
  55. // CHECK:STDOUT: } {
  56. // CHECK:STDOUT: %self.param: %X = value_param runtime_param0
  57. // CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%X [template = constants.%X]
  58. // CHECK:STDOUT: %self: %X = bind_name self, %self.param
  59. // CHECK:STDOUT: }
  60. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [template = constants.%complete_type]
  61. // CHECK:STDOUT: complete_type_witness = %complete_type
  62. // CHECK:STDOUT:
  63. // CHECK:STDOUT: !members:
  64. // CHECK:STDOUT: .Self = constants.%X
  65. // CHECK:STDOUT: .F = %F.decl
  66. // CHECK:STDOUT: }
  67. // CHECK:STDOUT:
  68. // CHECK:STDOUT: fn @F[%self.param_patt: %X]();
  69. // CHECK:STDOUT:
  70. // CHECK:STDOUT: fn @G(%x.param_patt: %X) {
  71. // CHECK:STDOUT: !entry:
  72. // CHECK:STDOUT: %x.ref.loc12_3: %X = name_ref x, %x
  73. // CHECK:STDOUT: %x.ref.loc12_6: %X = name_ref x, %x
  74. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, @X.%F.decl [template = constants.%F]
  75. // CHECK:STDOUT: %F.bound: <bound method> = bound_method %x.ref.loc12_6, %F.ref
  76. // CHECK:STDOUT: %F.call: init %empty_tuple.type = call %F.bound(%x.ref.loc12_6)
  77. // CHECK:STDOUT: return
  78. // CHECK:STDOUT: }
  79. // CHECK:STDOUT: