fail_addr_self.carbon 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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/convert.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/fail_addr_self.carbon
  12. // TIP: To dump output, run:
  13. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/fail_addr_self.carbon
  14. class Class {
  15. fn F[addr self: Class*]();
  16. // CHECK:STDERR: fail_addr_self.carbon:[[@LINE+4]]:8: error: `addr` can only be applied to a binding with a pointer type [AddrOnNonPointerType]
  17. // CHECK:STDERR: fn G[addr self: Class]();
  18. // CHECK:STDERR: ^~~~~~~~~~~~~~~~
  19. // CHECK:STDERR:
  20. fn G[addr self: Class]();
  21. }
  22. fn F(c: Class, p: Class*) {
  23. // CHECK:STDERR: fail_addr_self.carbon:[[@LINE+7]]:3: error: `addr self` method cannot be invoked on a value [AddrSelfIsNonRef]
  24. // CHECK:STDERR: c.F();
  25. // CHECK:STDERR: ^
  26. // CHECK:STDERR: fail_addr_self.carbon:[[@LINE-12]]:8: note: initializing function parameter [InCallToFunctionParam]
  27. // CHECK:STDERR: fn F[addr self: Class*]();
  28. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~
  29. // CHECK:STDERR:
  30. c.F();
  31. c.G();
  32. // This call is OK.
  33. (*p).F();
  34. (*p).G();
  35. }
  36. // CHECK:STDOUT: --- fail_addr_self.carbon
  37. // CHECK:STDOUT:
  38. // CHECK:STDOUT: constants {
  39. // CHECK:STDOUT: %Class: type = class_type @Class [concrete]
  40. // CHECK:STDOUT: %ptr.e71: type = ptr_type %Class [concrete]
  41. // CHECK:STDOUT: %pattern_type.796: type = pattern_type %ptr.e71 [concrete]
  42. // CHECK:STDOUT: %pattern_type.f6d: type = pattern_type auto [concrete]
  43. // CHECK:STDOUT: %Class.F.type: type = fn_type @Class.F [concrete]
  44. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  45. // CHECK:STDOUT: %Class.F: %Class.F.type = struct_value () [concrete]
  46. // CHECK:STDOUT: %pattern_type.761: type = pattern_type %Class [concrete]
  47. // CHECK:STDOUT: %Class.G.type: type = fn_type @Class.G [concrete]
  48. // CHECK:STDOUT: %Class.G: %Class.G.type = struct_value () [concrete]
  49. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  50. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete]
  51. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  52. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT:
  55. // CHECK:STDOUT: imports {
  56. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  57. // CHECK:STDOUT: import Core//prelude
  58. // CHECK:STDOUT: import Core//prelude/...
  59. // CHECK:STDOUT: }
  60. // CHECK:STDOUT: }
  61. // CHECK:STDOUT:
  62. // CHECK:STDOUT: file {
  63. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  64. // CHECK:STDOUT: .Core = imports.%Core
  65. // CHECK:STDOUT: .Class = %Class.decl
  66. // CHECK:STDOUT: .F = %F.decl
  67. // CHECK:STDOUT: }
  68. // CHECK:STDOUT: %Core.import = import Core
  69. // CHECK:STDOUT: %Class.decl: type = class_decl @Class [concrete = constants.%Class] {} {}
  70. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {
  71. // CHECK:STDOUT: %c.patt: %pattern_type.761 = binding_pattern c [concrete]
  72. // CHECK:STDOUT: %c.param_patt: %pattern_type.761 = value_param_pattern %c.patt, call_param0 [concrete]
  73. // CHECK:STDOUT: %p.patt: %pattern_type.796 = binding_pattern p [concrete]
  74. // CHECK:STDOUT: %p.param_patt: %pattern_type.796 = value_param_pattern %p.patt, call_param1 [concrete]
  75. // CHECK:STDOUT: } {
  76. // CHECK:STDOUT: %c.param: %Class = value_param call_param0
  77. // CHECK:STDOUT: %Class.ref.loc24_9: type = name_ref Class, file.%Class.decl [concrete = constants.%Class]
  78. // CHECK:STDOUT: %c: %Class = bind_name c, %c.param
  79. // CHECK:STDOUT: %p.param: %ptr.e71 = value_param call_param1
  80. // CHECK:STDOUT: %.loc24: type = splice_block %ptr [concrete = constants.%ptr.e71] {
  81. // CHECK:STDOUT: %Class.ref.loc24_19: type = name_ref Class, file.%Class.decl [concrete = constants.%Class]
  82. // CHECK:STDOUT: %ptr: type = ptr_type %Class.ref.loc24_19 [concrete = constants.%ptr.e71]
  83. // CHECK:STDOUT: }
  84. // CHECK:STDOUT: %p: %ptr.e71 = bind_name p, %p.param
  85. // CHECK:STDOUT: }
  86. // CHECK:STDOUT: }
  87. // CHECK:STDOUT:
  88. // CHECK:STDOUT: class @Class {
  89. // CHECK:STDOUT: %Class.F.decl: %Class.F.type = fn_decl @Class.F [concrete = constants.%Class.F] {
  90. // CHECK:STDOUT: %self.patt: %pattern_type.796 = binding_pattern self [concrete]
  91. // CHECK:STDOUT: %self.param_patt: %pattern_type.796 = value_param_pattern %self.patt, call_param0 [concrete]
  92. // CHECK:STDOUT: %.loc16_8: %pattern_type.f6d = addr_pattern %self.param_patt [concrete]
  93. // CHECK:STDOUT: } {
  94. // CHECK:STDOUT: %self.param: %ptr.e71 = value_param call_param0
  95. // CHECK:STDOUT: %.loc16_24: type = splice_block %ptr [concrete = constants.%ptr.e71] {
  96. // CHECK:STDOUT: %Class.ref: type = name_ref Class, file.%Class.decl [concrete = constants.%Class]
  97. // CHECK:STDOUT: %ptr: type = ptr_type %Class.ref [concrete = constants.%ptr.e71]
  98. // CHECK:STDOUT: }
  99. // CHECK:STDOUT: %self: %ptr.e71 = bind_name self, %self.param
  100. // CHECK:STDOUT: }
  101. // CHECK:STDOUT: %Class.G.decl: %Class.G.type = fn_decl @Class.G [concrete = constants.%Class.G] {
  102. // CHECK:STDOUT: %self.patt: %pattern_type.761 = binding_pattern self [concrete]
  103. // CHECK:STDOUT: %self.param_patt: %pattern_type.761 = value_param_pattern %self.patt, call_param0 [concrete]
  104. // CHECK:STDOUT: } {
  105. // CHECK:STDOUT: %self.param: %Class = value_param call_param0
  106. // CHECK:STDOUT: %Class.ref: type = name_ref Class, file.%Class.decl [concrete = constants.%Class]
  107. // CHECK:STDOUT: %self: %Class = bind_name self, %self.param
  108. // CHECK:STDOUT: }
  109. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness constants.%empty_struct_type [concrete = constants.%complete_type]
  110. // CHECK:STDOUT: complete_type_witness = %complete_type
  111. // CHECK:STDOUT:
  112. // CHECK:STDOUT: !members:
  113. // CHECK:STDOUT: .Self = constants.%Class
  114. // CHECK:STDOUT: .Class = <poisoned>
  115. // CHECK:STDOUT: .F = %Class.F.decl
  116. // CHECK:STDOUT: .G = %Class.G.decl
  117. // CHECK:STDOUT: }
  118. // CHECK:STDOUT:
  119. // CHECK:STDOUT: fn @Class.F(%self.param: %ptr.e71);
  120. // CHECK:STDOUT:
  121. // CHECK:STDOUT: fn @Class.G(%self.param: %Class);
  122. // CHECK:STDOUT:
  123. // CHECK:STDOUT: fn @F(%c.param: %Class, %p.param: %ptr.e71) {
  124. // CHECK:STDOUT: !entry:
  125. // CHECK:STDOUT: %c.ref.loc32: %Class = name_ref c, %c
  126. // CHECK:STDOUT: %F.ref.loc32: %Class.F.type = name_ref F, @Class.%Class.F.decl [concrete = constants.%Class.F]
  127. // CHECK:STDOUT: %Class.F.bound.loc32: <bound method> = bound_method %c.ref.loc32, %F.ref.loc32
  128. // CHECK:STDOUT: %.loc32: ref %Class = temporary_storage
  129. // CHECK:STDOUT: %addr.loc32: %ptr.e71 = addr_of %.loc32
  130. // CHECK:STDOUT: %Class.F.call.loc32: init %empty_tuple.type = call %Class.F.bound.loc32(%addr.loc32)
  131. // CHECK:STDOUT: %c.ref.loc34: %Class = name_ref c, %c
  132. // CHECK:STDOUT: %G.ref.loc34: %Class.G.type = name_ref G, @Class.%Class.G.decl [concrete = constants.%Class.G]
  133. // CHECK:STDOUT: %Class.G.bound.loc34: <bound method> = bound_method %c.ref.loc34, %G.ref.loc34
  134. // CHECK:STDOUT: %Class.G.call.loc34: init %empty_tuple.type = call %Class.G.bound.loc34(%c.ref.loc34)
  135. // CHECK:STDOUT: %p.ref.loc37: %ptr.e71 = name_ref p, %p
  136. // CHECK:STDOUT: %.loc37: ref %Class = deref %p.ref.loc37
  137. // CHECK:STDOUT: %F.ref.loc37: %Class.F.type = name_ref F, @Class.%Class.F.decl [concrete = constants.%Class.F]
  138. // CHECK:STDOUT: %Class.F.bound.loc37: <bound method> = bound_method %.loc37, %F.ref.loc37
  139. // CHECK:STDOUT: %addr.loc37: %ptr.e71 = addr_of %.loc37
  140. // CHECK:STDOUT: %Class.F.call.loc37: init %empty_tuple.type = call %Class.F.bound.loc37(%addr.loc37)
  141. // CHECK:STDOUT: %p.ref.loc39: %ptr.e71 = name_ref p, %p
  142. // CHECK:STDOUT: %.loc39_4.1: ref %Class = deref %p.ref.loc39
  143. // CHECK:STDOUT: %G.ref.loc39: %Class.G.type = name_ref G, @Class.%Class.G.decl [concrete = constants.%Class.G]
  144. // CHECK:STDOUT: %Class.G.bound.loc39: <bound method> = bound_method %.loc39_4.1, %G.ref.loc39
  145. // CHECK:STDOUT: %.loc39_4.2: %Class = bind_value %.loc39_4.1
  146. // CHECK:STDOUT: %Class.G.call.loc39: init %empty_tuple.type = call %Class.G.bound.loc39(%.loc39_4.2)
  147. // CHECK:STDOUT: return
  148. // CHECK:STDOUT: }
  149. // CHECK:STDOUT: