fail_method.carbon 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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/fail_method.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/fail_method.carbon
  10. class Class {
  11. fn NoSelf();
  12. fn WithSelf[self: Class]();
  13. }
  14. alias A = Class.WithSelf;
  15. fn F(c: Class) {
  16. c.NoSelf();
  17. c.WithSelf();
  18. Class.NoSelf();
  19. // CHECK:STDERR: fail_method.carbon:[[@LINE+7]]:3: ERROR: Missing object argument in method call.
  20. // CHECK:STDERR: Class.WithSelf();
  21. // CHECK:STDERR: ^~~~~~~~~~~~~~~
  22. // CHECK:STDERR: fail_method.carbon:[[@LINE-13]]:3: Calling function declared here.
  23. // CHECK:STDERR: fn WithSelf[self: Class]();
  24. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~
  25. // CHECK:STDERR:
  26. Class.WithSelf();
  27. // CHECK:STDERR: fail_method.carbon:[[@LINE+7]]:3: ERROR: 1 argument(s) passed to function expecting 0 argument(s).
  28. // CHECK:STDERR: Class.WithSelf(c);
  29. // CHECK:STDERR: ^~~~~~~~~~~~~~~
  30. // CHECK:STDERR: fail_method.carbon:[[@LINE-21]]:3: Calling function declared here.
  31. // CHECK:STDERR: fn WithSelf[self: Class]();
  32. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~
  33. // CHECK:STDERR:
  34. Class.WithSelf(c);
  35. // CHECK:STDERR: fail_method.carbon:[[@LINE+6]]:3: ERROR: Missing object argument in method call.
  36. // CHECK:STDERR: A();
  37. // CHECK:STDERR: ^~
  38. // CHECK:STDERR: fail_method.carbon:[[@LINE-30]]:3: Calling function declared here.
  39. // CHECK:STDERR: fn WithSelf[self: Class]();
  40. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~
  41. A();
  42. }
  43. // CHECK:STDOUT: --- fail_method.carbon
  44. // CHECK:STDOUT:
  45. // CHECK:STDOUT: constants {
  46. // CHECK:STDOUT: %Class: type = class_type @Class [template]
  47. // CHECK:STDOUT: %NoSelf.type: type = fn_type @NoSelf [template]
  48. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  49. // CHECK:STDOUT: %NoSelf: %NoSelf.type = struct_value () [template]
  50. // CHECK:STDOUT: %WithSelf.type: type = fn_type @WithSelf [template]
  51. // CHECK:STDOUT: %WithSelf: %WithSelf.type = struct_value () [template]
  52. // CHECK:STDOUT: %.2: type = struct_type {} [template]
  53. // CHECK:STDOUT: %.3: type = ptr_type %.2 [template]
  54. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  55. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  56. // CHECK:STDOUT: }
  57. // CHECK:STDOUT:
  58. // CHECK:STDOUT: file {
  59. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  60. // CHECK:STDOUT: .Core = %Core
  61. // CHECK:STDOUT: .Class = %Class.decl
  62. // CHECK:STDOUT: .A = %A
  63. // CHECK:STDOUT: .F = %F.decl
  64. // CHECK:STDOUT: }
  65. // CHECK:STDOUT: %Core.import = import Core
  66. // CHECK:STDOUT: %Core: <namespace> = namespace %Core.import, [template] {
  67. // CHECK:STDOUT: import Core//prelude
  68. // CHECK:STDOUT: import Core//prelude/operators
  69. // CHECK:STDOUT: import Core//prelude/types
  70. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  71. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  72. // CHECK:STDOUT: import Core//prelude/operators/comparison
  73. // CHECK:STDOUT: import Core//prelude/types/bool
  74. // CHECK:STDOUT: }
  75. // CHECK:STDOUT: %Class.decl: type = class_decl @Class [template = constants.%Class] {}
  76. // CHECK:STDOUT: %Class.ref.loc16: type = name_ref Class, %Class.decl [template = constants.%Class]
  77. // CHECK:STDOUT: %WithSelf.ref: %WithSelf.type = name_ref WithSelf, @Class.%WithSelf.decl [template = constants.%WithSelf]
  78. // CHECK:STDOUT: %A: %WithSelf.type = bind_alias A, @Class.%WithSelf.decl [template = constants.%WithSelf]
  79. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  80. // CHECK:STDOUT: %Class.ref.loc18: type = name_ref Class, %Class.decl [template = constants.%Class]
  81. // CHECK:STDOUT: %c.loc18_6.1: %Class = param c
  82. // CHECK:STDOUT: @F.%c: %Class = bind_name c, %c.loc18_6.1
  83. // CHECK:STDOUT: }
  84. // CHECK:STDOUT: }
  85. // CHECK:STDOUT:
  86. // CHECK:STDOUT: class @Class {
  87. // CHECK:STDOUT: %NoSelf.decl: %NoSelf.type = fn_decl @NoSelf [template = constants.%NoSelf] {}
  88. // CHECK:STDOUT: %WithSelf.decl: %WithSelf.type = fn_decl @WithSelf [template = constants.%WithSelf] {
  89. // CHECK:STDOUT: %Class.ref: type = name_ref Class, file.%Class.decl [template = constants.%Class]
  90. // CHECK:STDOUT: %self.loc13_15.1: %Class = param self
  91. // CHECK:STDOUT: %self.loc13_15.2: %Class = bind_name self, %self.loc13_15.1
  92. // CHECK:STDOUT: }
  93. // CHECK:STDOUT:
  94. // CHECK:STDOUT: !members:
  95. // CHECK:STDOUT: .Self = constants.%Class
  96. // CHECK:STDOUT: .NoSelf = %NoSelf.decl
  97. // CHECK:STDOUT: .WithSelf = %WithSelf.decl
  98. // CHECK:STDOUT: }
  99. // CHECK:STDOUT:
  100. // CHECK:STDOUT: fn @NoSelf();
  101. // CHECK:STDOUT:
  102. // CHECK:STDOUT: fn @WithSelf[@Class.%self.loc13_15.2: %Class]();
  103. // CHECK:STDOUT:
  104. // CHECK:STDOUT: fn @F(%c: %Class) {
  105. // CHECK:STDOUT: !entry:
  106. // CHECK:STDOUT: %c.ref.loc19: %Class = name_ref c, %c
  107. // CHECK:STDOUT: %NoSelf.ref.loc19: %NoSelf.type = name_ref NoSelf, @Class.%NoSelf.decl [template = constants.%NoSelf]
  108. // CHECK:STDOUT: %NoSelf.call.loc19: init %.1 = call %NoSelf.ref.loc19()
  109. // CHECK:STDOUT: %c.ref.loc20: %Class = name_ref c, %c
  110. // CHECK:STDOUT: %WithSelf.ref.loc20: %WithSelf.type = name_ref WithSelf, @Class.%WithSelf.decl [template = constants.%WithSelf]
  111. // CHECK:STDOUT: %.loc20: <bound method> = bound_method %c.ref.loc20, %WithSelf.ref.loc20
  112. // CHECK:STDOUT: %WithSelf.call.loc20: init %.1 = call %.loc20(%c.ref.loc20)
  113. // CHECK:STDOUT: %Class.ref.loc22: type = name_ref Class, file.%Class.decl [template = constants.%Class]
  114. // CHECK:STDOUT: %NoSelf.ref.loc22: %NoSelf.type = name_ref NoSelf, @Class.%NoSelf.decl [template = constants.%NoSelf]
  115. // CHECK:STDOUT: %NoSelf.call.loc22: init %.1 = call %NoSelf.ref.loc22()
  116. // CHECK:STDOUT: %Class.ref.loc30: type = name_ref Class, file.%Class.decl [template = constants.%Class]
  117. // CHECK:STDOUT: %WithSelf.ref.loc30: %WithSelf.type = name_ref WithSelf, @Class.%WithSelf.decl [template = constants.%WithSelf]
  118. // CHECK:STDOUT: %WithSelf.call.loc30: init %.1 = call %WithSelf.ref.loc30(<invalid>) [template = <error>]
  119. // CHECK:STDOUT: %Class.ref.loc38: type = name_ref Class, file.%Class.decl [template = constants.%Class]
  120. // CHECK:STDOUT: %WithSelf.ref.loc38: %WithSelf.type = name_ref WithSelf, @Class.%WithSelf.decl [template = constants.%WithSelf]
  121. // CHECK:STDOUT: %c.ref.loc38: %Class = name_ref c, %c
  122. // CHECK:STDOUT: %WithSelf.call.loc38: init %.1 = call %WithSelf.ref.loc38(<invalid>) [template = <error>]
  123. // CHECK:STDOUT: %A.ref: %WithSelf.type = name_ref A, file.%A [template = constants.%WithSelf]
  124. // CHECK:STDOUT: %WithSelf.call.loc46: init %.1 = call %A.ref(<invalid>) [template = <error>]
  125. // CHECK:STDOUT: return
  126. // CHECK:STDOUT: }
  127. // CHECK:STDOUT: