fail_method.carbon 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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: %NoSelf: type = fn_type @NoSelf [template]
  44. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  45. // CHECK:STDOUT: %struct.1: NoSelf = struct_value () [template]
  46. // CHECK:STDOUT: %WithSelf: type = fn_type @WithSelf [template]
  47. // CHECK:STDOUT: %struct.2: WithSelf = struct_value () [template]
  48. // CHECK:STDOUT: %.2: type = struct_type {} [template]
  49. // CHECK:STDOUT: %F: type = fn_type @F [template]
  50. // CHECK:STDOUT: %struct.3: F = struct_value () [template]
  51. // CHECK:STDOUT: %.3: type = ptr_type {} [template]
  52. // CHECK:STDOUT: }
  53. // CHECK:STDOUT:
  54. // CHECK:STDOUT: file {
  55. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  56. // CHECK:STDOUT: .Core = %Core
  57. // CHECK:STDOUT: .Class = %Class.decl
  58. // CHECK:STDOUT: .A = %A
  59. // CHECK:STDOUT: .F = %F.decl
  60. // CHECK:STDOUT: }
  61. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  62. // CHECK:STDOUT: %Class.decl: type = class_decl @Class [template = constants.%Class] {}
  63. // CHECK:STDOUT: %Class.ref.loc12: type = name_ref Class, %Class.decl [template = constants.%Class]
  64. // CHECK:STDOUT: %WithSelf.ref: WithSelf = name_ref WithSelf, @Class.%WithSelf.decl [template = constants.%struct.2]
  65. // CHECK:STDOUT: %A: WithSelf = bind_alias A, @Class.%WithSelf.decl [template = constants.%struct.2]
  66. // CHECK:STDOUT: %F.decl: F = fn_decl @F [template = constants.%struct.3] {
  67. // CHECK:STDOUT: %Class.ref.loc14: type = name_ref Class, %Class.decl [template = constants.%Class]
  68. // CHECK:STDOUT: %c.loc14_6.1: Class = param c
  69. // CHECK:STDOUT: @F.%c: Class = bind_name c, %c.loc14_6.1
  70. // CHECK:STDOUT: }
  71. // CHECK:STDOUT: }
  72. // CHECK:STDOUT:
  73. // CHECK:STDOUT: class @Class {
  74. // CHECK:STDOUT: %NoSelf.decl: NoSelf = fn_decl @NoSelf [template = constants.%struct.1] {}
  75. // CHECK:STDOUT: %WithSelf.decl: WithSelf = fn_decl @WithSelf [template = constants.%struct.2] {
  76. // CHECK:STDOUT: %Class.ref: type = name_ref Class, file.%Class.decl [template = constants.%Class]
  77. // CHECK:STDOUT: %self.loc9_15.1: Class = param self
  78. // CHECK:STDOUT: %self.loc9_15.2: Class = bind_name self, %self.loc9_15.1
  79. // CHECK:STDOUT: }
  80. // CHECK:STDOUT:
  81. // CHECK:STDOUT: !members:
  82. // CHECK:STDOUT: .Self = constants.%Class
  83. // CHECK:STDOUT: .NoSelf = %NoSelf.decl
  84. // CHECK:STDOUT: .WithSelf = %WithSelf.decl
  85. // CHECK:STDOUT: }
  86. // CHECK:STDOUT:
  87. // CHECK:STDOUT: fn @NoSelf();
  88. // CHECK:STDOUT:
  89. // CHECK:STDOUT: fn @WithSelf[@Class.%self.loc9_15.2: Class]();
  90. // CHECK:STDOUT:
  91. // CHECK:STDOUT: fn @F(%c: Class) {
  92. // CHECK:STDOUT: !entry:
  93. // CHECK:STDOUT: %c.ref.loc15: Class = name_ref c, %c
  94. // CHECK:STDOUT: %NoSelf.ref.loc15: NoSelf = name_ref NoSelf, @Class.%NoSelf.decl [template = constants.%struct.1]
  95. // CHECK:STDOUT: %NoSelf.call.loc15: init () = call %NoSelf.ref.loc15()
  96. // CHECK:STDOUT: %c.ref.loc16: Class = name_ref c, %c
  97. // CHECK:STDOUT: %WithSelf.ref.loc16: WithSelf = name_ref WithSelf, @Class.%WithSelf.decl [template = constants.%struct.2]
  98. // CHECK:STDOUT: %.loc16: <bound method> = bound_method %c.ref.loc16, %WithSelf.ref.loc16
  99. // CHECK:STDOUT: %WithSelf.call.loc16: init () = call %.loc16(%c.ref.loc16)
  100. // CHECK:STDOUT: %Class.ref.loc18: type = name_ref Class, file.%Class.decl [template = constants.%Class]
  101. // CHECK:STDOUT: %NoSelf.ref.loc18: NoSelf = name_ref NoSelf, @Class.%NoSelf.decl [template = constants.%struct.1]
  102. // CHECK:STDOUT: %NoSelf.call.loc18: init () = call %NoSelf.ref.loc18()
  103. // CHECK:STDOUT: %Class.ref.loc26: type = name_ref Class, file.%Class.decl [template = constants.%Class]
  104. // CHECK:STDOUT: %WithSelf.ref.loc26: WithSelf = name_ref WithSelf, @Class.%WithSelf.decl [template = constants.%struct.2]
  105. // CHECK:STDOUT: %WithSelf.call.loc26: init () = call %WithSelf.ref.loc26(<invalid>) [template = <error>]
  106. // CHECK:STDOUT: %Class.ref.loc34: type = name_ref Class, file.%Class.decl [template = constants.%Class]
  107. // CHECK:STDOUT: %WithSelf.ref.loc34: WithSelf = name_ref WithSelf, @Class.%WithSelf.decl [template = constants.%struct.2]
  108. // CHECK:STDOUT: %c.ref.loc34: Class = name_ref c, %c
  109. // CHECK:STDOUT: %WithSelf.call.loc34: init () = call %WithSelf.ref.loc34(<invalid>) [template = <error>]
  110. // CHECK:STDOUT: %A.ref: WithSelf = name_ref A, file.%A [template = constants.%struct.2]
  111. // CHECK:STDOUT: %WithSelf.call.loc42: init () = call %A.ref(<invalid>) [template = <error>]
  112. // CHECK:STDOUT: return
  113. // CHECK:STDOUT: }
  114. // CHECK:STDOUT: