fail_method.carbon 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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/fail_method.carbon
  11. // TIP: To dump output, run:
  12. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/fail_method.carbon
  13. class Class {
  14. fn NoSelf();
  15. fn WithSelf[self: Class]();
  16. }
  17. alias A = Class.WithSelf;
  18. fn F(c: Class) {
  19. c.NoSelf();
  20. c.WithSelf();
  21. Class.NoSelf();
  22. // CHECK:STDERR: fail_method.carbon:[[@LINE+7]]:3: error: missing object argument in method call [MissingObjectInMethodCall]
  23. // CHECK:STDERR: Class.WithSelf();
  24. // CHECK:STDERR: ^~~~~~~~~~~~~~~~
  25. // CHECK:STDERR: fail_method.carbon:[[@LINE-13]]:3: note: calling function declared here [InCallToFunction]
  26. // CHECK:STDERR: fn WithSelf[self: Class]();
  27. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~
  28. // CHECK:STDERR:
  29. Class.WithSelf();
  30. // CHECK:STDERR: fail_method.carbon:[[@LINE+7]]:3: error: 1 argument passed to function expecting 0 arguments [CallArgCountMismatch]
  31. // CHECK:STDERR: Class.WithSelf(c);
  32. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~
  33. // CHECK:STDERR: fail_method.carbon:[[@LINE-21]]:3: note: calling function declared here [InCallToEntity]
  34. // CHECK:STDERR: fn WithSelf[self: Class]();
  35. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~
  36. // CHECK:STDERR:
  37. Class.WithSelf(c);
  38. // CHECK:STDERR: fail_method.carbon:[[@LINE+7]]:3: error: missing object argument in method call [MissingObjectInMethodCall]
  39. // CHECK:STDERR: A();
  40. // CHECK:STDERR: ^~~
  41. // CHECK:STDERR: fail_method.carbon:[[@LINE-30]]:3: note: calling function declared here [InCallToFunction]
  42. // CHECK:STDERR: fn WithSelf[self: Class]();
  43. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~
  44. // CHECK:STDERR:
  45. A();
  46. }
  47. // CHECK:STDOUT: --- fail_method.carbon
  48. // CHECK:STDOUT:
  49. // CHECK:STDOUT: constants {
  50. // CHECK:STDOUT: %Class: type = class_type @Class [concrete]
  51. // CHECK:STDOUT: %NoSelf.type: type = fn_type @NoSelf [concrete]
  52. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  53. // CHECK:STDOUT: %NoSelf: %NoSelf.type = struct_value () [concrete]
  54. // CHECK:STDOUT: %pattern_type: type = pattern_type %Class [concrete]
  55. // CHECK:STDOUT: %WithSelf.type: type = fn_type @WithSelf [concrete]
  56. // CHECK:STDOUT: %WithSelf: %WithSelf.type = struct_value () [concrete]
  57. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  58. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete]
  59. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  60. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  61. // CHECK:STDOUT: }
  62. // CHECK:STDOUT:
  63. // CHECK:STDOUT: imports {
  64. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  65. // CHECK:STDOUT: import Core//prelude
  66. // CHECK:STDOUT: import Core//prelude/...
  67. // CHECK:STDOUT: }
  68. // CHECK:STDOUT: }
  69. // CHECK:STDOUT:
  70. // CHECK:STDOUT: file {
  71. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  72. // CHECK:STDOUT: .Core = imports.%Core
  73. // CHECK:STDOUT: .Class = %Class.decl
  74. // CHECK:STDOUT: .A = %A
  75. // CHECK:STDOUT: .F = %F.decl
  76. // CHECK:STDOUT: }
  77. // CHECK:STDOUT: %Core.import = import Core
  78. // CHECK:STDOUT: %Class.decl: type = class_decl @Class [concrete = constants.%Class] {} {}
  79. // CHECK:STDOUT: %Class.ref: type = name_ref Class, %Class.decl [concrete = constants.%Class]
  80. // CHECK:STDOUT: %WithSelf.ref: %WithSelf.type = name_ref WithSelf, @Class.%WithSelf.decl [concrete = constants.%WithSelf]
  81. // CHECK:STDOUT: %A: %WithSelf.type = bind_alias A, @Class.%WithSelf.decl [concrete = constants.%WithSelf]
  82. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {
  83. // CHECK:STDOUT: %c.patt: %pattern_type = binding_pattern c [concrete]
  84. // CHECK:STDOUT: %c.param_patt: %pattern_type = value_param_pattern %c.patt, call_param0 [concrete]
  85. // CHECK:STDOUT: } {
  86. // CHECK:STDOUT: %c.param: %Class = value_param call_param0
  87. // CHECK:STDOUT: %Class.ref.loc21: type = name_ref Class, file.%Class.decl [concrete = constants.%Class]
  88. // CHECK:STDOUT: %c: %Class = bind_name c, %c.param
  89. // CHECK:STDOUT: }
  90. // CHECK:STDOUT: }
  91. // CHECK:STDOUT:
  92. // CHECK:STDOUT: class @Class {
  93. // CHECK:STDOUT: %NoSelf.decl: %NoSelf.type = fn_decl @NoSelf [concrete = constants.%NoSelf] {} {}
  94. // CHECK:STDOUT: %WithSelf.decl: %WithSelf.type = fn_decl @WithSelf [concrete = constants.%WithSelf] {
  95. // CHECK:STDOUT: %self.patt: %pattern_type = binding_pattern self [concrete]
  96. // CHECK:STDOUT: %self.param_patt: %pattern_type = value_param_pattern %self.patt, call_param0 [concrete]
  97. // CHECK:STDOUT: } {
  98. // CHECK:STDOUT: %self.param: %Class = value_param call_param0
  99. // CHECK:STDOUT: %Class.ref: type = name_ref Class, file.%Class.decl [concrete = constants.%Class]
  100. // CHECK:STDOUT: %self: %Class = bind_name self, %self.param
  101. // CHECK:STDOUT: }
  102. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete = constants.%empty_struct_type]
  103. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete = constants.%complete_type]
  104. // CHECK:STDOUT: complete_type_witness = %complete_type
  105. // CHECK:STDOUT:
  106. // CHECK:STDOUT: !members:
  107. // CHECK:STDOUT: .Self = constants.%Class
  108. // CHECK:STDOUT: .NoSelf = %NoSelf.decl
  109. // CHECK:STDOUT: .Class = <poisoned>
  110. // CHECK:STDOUT: .WithSelf = %WithSelf.decl
  111. // CHECK:STDOUT: }
  112. // CHECK:STDOUT:
  113. // CHECK:STDOUT: fn @NoSelf();
  114. // CHECK:STDOUT:
  115. // CHECK:STDOUT: fn @WithSelf(%self.param: %Class);
  116. // CHECK:STDOUT:
  117. // CHECK:STDOUT: fn @F(%c.param: %Class) {
  118. // CHECK:STDOUT: !entry:
  119. // CHECK:STDOUT: %c.ref.loc22: %Class = name_ref c, %c
  120. // CHECK:STDOUT: %NoSelf.ref.loc22: %NoSelf.type = name_ref NoSelf, @Class.%NoSelf.decl [concrete = constants.%NoSelf]
  121. // CHECK:STDOUT: %NoSelf.call.loc22: init %empty_tuple.type = call %NoSelf.ref.loc22()
  122. // CHECK:STDOUT: %c.ref.loc23: %Class = name_ref c, %c
  123. // CHECK:STDOUT: %WithSelf.ref.loc23: %WithSelf.type = name_ref WithSelf, @Class.%WithSelf.decl [concrete = constants.%WithSelf]
  124. // CHECK:STDOUT: %WithSelf.bound: <bound method> = bound_method %c.ref.loc23, %WithSelf.ref.loc23
  125. // CHECK:STDOUT: %WithSelf.call.loc23: init %empty_tuple.type = call %WithSelf.bound(%c.ref.loc23)
  126. // CHECK:STDOUT: %Class.ref.loc25: type = name_ref Class, file.%Class.decl [concrete = constants.%Class]
  127. // CHECK:STDOUT: %NoSelf.ref.loc25: %NoSelf.type = name_ref NoSelf, @Class.%NoSelf.decl [concrete = constants.%NoSelf]
  128. // CHECK:STDOUT: %NoSelf.call.loc25: init %empty_tuple.type = call %NoSelf.ref.loc25()
  129. // CHECK:STDOUT: %Class.ref.loc33: type = name_ref Class, file.%Class.decl [concrete = constants.%Class]
  130. // CHECK:STDOUT: %WithSelf.ref.loc33: %WithSelf.type = name_ref WithSelf, @Class.%WithSelf.decl [concrete = constants.%WithSelf]
  131. // CHECK:STDOUT: %WithSelf.call.loc33: init %empty_tuple.type = call %WithSelf.ref.loc33(<error>)
  132. // CHECK:STDOUT: %Class.ref.loc41: type = name_ref Class, file.%Class.decl [concrete = constants.%Class]
  133. // CHECK:STDOUT: %WithSelf.ref.loc41: %WithSelf.type = name_ref WithSelf, @Class.%WithSelf.decl [concrete = constants.%WithSelf]
  134. // CHECK:STDOUT: %c.ref.loc41: %Class = name_ref c, %c
  135. // CHECK:STDOUT: %A.ref: %WithSelf.type = name_ref A, file.%A [concrete = constants.%WithSelf]
  136. // CHECK:STDOUT: %WithSelf.call.loc50: init %empty_tuple.type = call %A.ref(<error>)
  137. // CHECK:STDOUT: return
  138. // CHECK:STDOUT: }
  139. // CHECK:STDOUT: