fail_method.carbon 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. class Class {
  7. fn NoSelf();
  8. fn WithSelf[self: Class]();
  9. }
  10. alias A = Class.WithSelf;
  11. fn F(c: Class) {
  12. c.NoSelf();
  13. c.WithSelf();
  14. Class.NoSelf();
  15. // CHECK:STDERR: fail_method.carbon:[[@LINE+7]]:3: ERROR: Missing object argument in method call.
  16. // CHECK:STDERR: Class.WithSelf();
  17. // CHECK:STDERR: ^~~~~~~~~~~~~~~
  18. // CHECK:STDERR: fail_method.carbon:[[@LINE-13]]:3: Calling function declared here.
  19. // CHECK:STDERR: fn WithSelf[self: Class]();
  20. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~
  21. // CHECK:STDERR:
  22. Class.WithSelf();
  23. // CHECK:STDERR: fail_method.carbon:[[@LINE+7]]:3: ERROR: 1 argument(s) passed to function expecting 0 argument(s).
  24. // CHECK:STDERR: Class.WithSelf(c);
  25. // CHECK:STDERR: ^~~~~~~~~~~~~~~
  26. // CHECK:STDERR: fail_method.carbon:[[@LINE-21]]:3: Calling function declared here.
  27. // CHECK:STDERR: fn WithSelf[self: Class]();
  28. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~
  29. // CHECK:STDERR:
  30. Class.WithSelf(c);
  31. // CHECK:STDERR: fail_method.carbon:[[@LINE+6]]:3: ERROR: Missing object argument in method call.
  32. // CHECK:STDERR: A();
  33. // CHECK:STDERR: ^~
  34. // CHECK:STDERR: fail_method.carbon:[[@LINE-30]]:3: Calling function declared here.
  35. // CHECK:STDERR: fn WithSelf[self: Class]();
  36. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~
  37. A();
  38. }
  39. // CHECK:STDOUT: --- fail_method.carbon
  40. // CHECK:STDOUT:
  41. // CHECK:STDOUT: constants {
  42. // CHECK:STDOUT: %Class: type = class_type @Class [template]
  43. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  44. // CHECK:STDOUT: %.2: type = tuple_type () [template]
  45. // CHECK:STDOUT: %.3: type = ptr_type {} [template]
  46. // CHECK:STDOUT: }
  47. // CHECK:STDOUT:
  48. // CHECK:STDOUT: file {
  49. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  50. // CHECK:STDOUT: .Core = %Core
  51. // CHECK:STDOUT: .Class = %Class.decl
  52. // CHECK:STDOUT: .A = %A
  53. // CHECK:STDOUT: .F = %F
  54. // CHECK:STDOUT: }
  55. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  56. // CHECK:STDOUT: %Class.decl: type = class_decl @Class [template = constants.%Class] {}
  57. // CHECK:STDOUT: %Class.ref.loc12: type = name_ref Class, %Class.decl [template = constants.%Class]
  58. // CHECK:STDOUT: %WithSelf.ref: <function> = name_ref WithSelf, @Class.%WithSelf [template = @Class.%WithSelf]
  59. // CHECK:STDOUT: %A: <function> = bind_alias A, @Class.%WithSelf [template = @Class.%WithSelf]
  60. // CHECK:STDOUT: %F: <function> = fn_decl @F [template] {
  61. // CHECK:STDOUT: %Class.ref.loc14: type = name_ref Class, %Class.decl [template = constants.%Class]
  62. // CHECK:STDOUT: %c.loc14_6.1: Class = param c
  63. // CHECK:STDOUT: @F.%c: Class = bind_name c, %c.loc14_6.1
  64. // CHECK:STDOUT: }
  65. // CHECK:STDOUT: }
  66. // CHECK:STDOUT:
  67. // CHECK:STDOUT: class @Class {
  68. // CHECK:STDOUT: %NoSelf: <function> = fn_decl @NoSelf [template] {}
  69. // CHECK:STDOUT: %WithSelf: <function> = fn_decl @WithSelf [template] {
  70. // CHECK:STDOUT: %Class.ref: type = name_ref Class, file.%Class.decl [template = constants.%Class]
  71. // CHECK:STDOUT: %self.loc9_15.1: Class = param self
  72. // CHECK:STDOUT: %self.loc9_15.2: Class = bind_name self, %self.loc9_15.1
  73. // CHECK:STDOUT: }
  74. // CHECK:STDOUT:
  75. // CHECK:STDOUT: !members:
  76. // CHECK:STDOUT: .Self = constants.%Class
  77. // CHECK:STDOUT: .NoSelf = %NoSelf
  78. // CHECK:STDOUT: .WithSelf = %WithSelf
  79. // CHECK:STDOUT: }
  80. // CHECK:STDOUT:
  81. // CHECK:STDOUT: fn @NoSelf();
  82. // CHECK:STDOUT:
  83. // CHECK:STDOUT: fn @WithSelf[@Class.%self.loc9_15.2: Class]();
  84. // CHECK:STDOUT:
  85. // CHECK:STDOUT: fn @F(%c: Class) {
  86. // CHECK:STDOUT: !entry:
  87. // CHECK:STDOUT: %c.ref.loc15: Class = name_ref c, %c
  88. // CHECK:STDOUT: %NoSelf.ref.loc15: <function> = name_ref NoSelf, @Class.%NoSelf [template = @Class.%NoSelf]
  89. // CHECK:STDOUT: %.loc15: init () = call %NoSelf.ref.loc15()
  90. // CHECK:STDOUT: %c.ref.loc16: Class = name_ref c, %c
  91. // CHECK:STDOUT: %WithSelf.ref.loc16: <function> = name_ref WithSelf, @Class.%WithSelf [template = @Class.%WithSelf]
  92. // CHECK:STDOUT: %.loc16_4: <bound method> = bound_method %c.ref.loc16, %WithSelf.ref.loc16
  93. // CHECK:STDOUT: %.loc16_13: init () = call %.loc16_4(%c.ref.loc16)
  94. // CHECK:STDOUT: %Class.ref.loc18: type = name_ref Class, file.%Class.decl [template = constants.%Class]
  95. // CHECK:STDOUT: %NoSelf.ref.loc18: <function> = name_ref NoSelf, @Class.%NoSelf [template = @Class.%NoSelf]
  96. // CHECK:STDOUT: %.loc18: init () = call %NoSelf.ref.loc18()
  97. // CHECK:STDOUT: %Class.ref.loc26: type = name_ref Class, file.%Class.decl [template = constants.%Class]
  98. // CHECK:STDOUT: %WithSelf.ref.loc26: <function> = name_ref WithSelf, @Class.%WithSelf [template = @Class.%WithSelf]
  99. // CHECK:STDOUT: %.loc26: init () = call %WithSelf.ref.loc26(<invalid>) [template = <error>]
  100. // CHECK:STDOUT: %Class.ref.loc34: type = name_ref Class, file.%Class.decl [template = constants.%Class]
  101. // CHECK:STDOUT: %WithSelf.ref.loc34: <function> = name_ref WithSelf, @Class.%WithSelf [template = @Class.%WithSelf]
  102. // CHECK:STDOUT: %c.ref.loc34: Class = name_ref c, %c
  103. // CHECK:STDOUT: %.loc34: init () = call %WithSelf.ref.loc34(<invalid>) [template = <error>]
  104. // CHECK:STDOUT: %A.ref: <function> = name_ref A, file.%A [template = @Class.%WithSelf]
  105. // CHECK:STDOUT: %.loc42: init () = call %A.ref(<invalid>) [template = <error>]
  106. // CHECK:STDOUT: return
  107. // CHECK:STDOUT: }
  108. // CHECK:STDOUT: