fail_addr_self.carbon 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 F[addr self: Class*]();
  8. fn G[addr self: Class]();
  9. }
  10. fn F(c: Class, p: Class*) {
  11. // CHECK:STDERR: fail_addr_self.carbon:[[@LINE+6]]:6: ERROR: `addr self` method cannot be invoked on a value.
  12. // CHECK:STDERR: c.F();
  13. // CHECK:STDERR: ^
  14. // CHECK:STDERR: fail_addr_self.carbon:[[@LINE-8]]:13: Initializing `addr self` parameter of method declared here.
  15. // CHECK:STDERR: fn F[addr self: Class*]();
  16. // CHECK:STDERR: ^~~~
  17. c.F();
  18. // CHECK:STDERR: fail_addr_self.carbon:[[@LINE+6]]:6: ERROR: `addr self` method cannot be invoked on a value.
  19. // CHECK:STDERR: c.G();
  20. // CHECK:STDERR: ^
  21. // CHECK:STDERR: fail_addr_self.carbon:[[@LINE-15]]:13: Initializing `addr self` parameter of method declared here.
  22. // CHECK:STDERR: fn G[addr self: Class]();
  23. // CHECK:STDERR: ^~~~
  24. c.G();
  25. // This call is OK.
  26. (*p).F();
  27. // CHECK:STDERR: fail_addr_self.carbon:[[@LINE+6]]:3: ERROR: Cannot implicitly convert from `Class*` to `Class`.
  28. // CHECK:STDERR: (*p).G();
  29. // CHECK:STDERR: ^~~~~~~
  30. // CHECK:STDERR: fail_addr_self.carbon:[[@LINE-26]]:13: Initializing `addr self` parameter of method declared here.
  31. // CHECK:STDERR: fn G[addr self: Class]();
  32. // CHECK:STDERR: ^~~~
  33. (*p).G();
  34. }
  35. // CHECK:STDOUT: --- fail_addr_self.carbon
  36. // CHECK:STDOUT:
  37. // CHECK:STDOUT: constants {
  38. // CHECK:STDOUT: %Class: type = class_type @Class [template]
  39. // CHECK:STDOUT: %.1: type = ptr_type Class [template]
  40. // CHECK:STDOUT: %.2: type = struct_type {} [template]
  41. // CHECK:STDOUT: %.3: type = tuple_type () [template]
  42. // CHECK:STDOUT: %.4: type = ptr_type {} [template]
  43. // CHECK:STDOUT: }
  44. // CHECK:STDOUT:
  45. // CHECK:STDOUT: file {
  46. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  47. // CHECK:STDOUT: .Class = %Class.decl
  48. // CHECK:STDOUT: .F = %F
  49. // CHECK:STDOUT: }
  50. // CHECK:STDOUT: %Class.decl: type = class_decl @Class [template = constants.%Class] {}
  51. // CHECK:STDOUT: %F: <function> = fn_decl @F.2 [template] {
  52. // CHECK:STDOUT: %Class.ref.loc12_9: type = name_ref Class, %Class.decl [template = constants.%Class]
  53. // CHECK:STDOUT: %c.loc12_6.1: Class = param c
  54. // CHECK:STDOUT: @F.2.%c: Class = bind_name c, %c.loc12_6.1
  55. // CHECK:STDOUT: %Class.ref.loc12_19: type = name_ref Class, %Class.decl [template = constants.%Class]
  56. // CHECK:STDOUT: %.loc12: type = ptr_type Class [template = constants.%.1]
  57. // CHECK:STDOUT: %p.loc12_16.1: Class* = param p
  58. // CHECK:STDOUT: @F.2.%p: Class* = bind_name p, %p.loc12_16.1
  59. // CHECK:STDOUT: }
  60. // CHECK:STDOUT: }
  61. // CHECK:STDOUT:
  62. // CHECK:STDOUT: class @Class {
  63. // CHECK:STDOUT: %F: <function> = fn_decl @F.1 [template] {
  64. // CHECK:STDOUT: %Class.ref.loc8: type = name_ref Class, file.%Class.decl [template = constants.%Class]
  65. // CHECK:STDOUT: %.loc8_24: type = ptr_type Class [template = constants.%.1]
  66. // CHECK:STDOUT: %self.loc8_13.1: Class* = param self
  67. // CHECK:STDOUT: %self.loc8_13.3: Class* = bind_name self, %self.loc8_13.1
  68. // CHECK:STDOUT: %.loc8_8: Class* = addr_pattern %self.loc8_13.3
  69. // CHECK:STDOUT: }
  70. // CHECK:STDOUT: %G: <function> = fn_decl @G [template] {
  71. // CHECK:STDOUT: %Class.ref.loc9: type = name_ref Class, file.%Class.decl [template = constants.%Class]
  72. // CHECK:STDOUT: %self.loc9_13.1: Class = param self
  73. // CHECK:STDOUT: %self.loc9_13.3: Class = bind_name self, %self.loc9_13.1
  74. // CHECK:STDOUT: %.loc9: Class = addr_pattern %self.loc9_13.3
  75. // CHECK:STDOUT: }
  76. // CHECK:STDOUT:
  77. // CHECK:STDOUT: !members:
  78. // CHECK:STDOUT: .Self = constants.%Class
  79. // CHECK:STDOUT: .F = %F
  80. // CHECK:STDOUT: .G = %G
  81. // CHECK:STDOUT: }
  82. // CHECK:STDOUT:
  83. // CHECK:STDOUT: fn @F.1[addr @Class.%self.loc8_13.3: Class*]();
  84. // CHECK:STDOUT:
  85. // CHECK:STDOUT: fn @G[addr @Class.%self.loc9_13.3: Class]();
  86. // CHECK:STDOUT:
  87. // CHECK:STDOUT: fn @F.2(%c: Class, %p: Class*) {
  88. // CHECK:STDOUT: !entry:
  89. // CHECK:STDOUT: %c.ref.loc19: Class = name_ref c, %c
  90. // CHECK:STDOUT: %F.ref.loc19: <function> = name_ref F, @Class.%F [template = @Class.%F]
  91. // CHECK:STDOUT: %.loc19_4: <bound method> = bound_method %c.ref.loc19, %F.ref.loc19
  92. // CHECK:STDOUT: %.loc19_6: init () = call %.loc19_4(<invalid>) [template = <error>]
  93. // CHECK:STDOUT: %c.ref.loc27: Class = name_ref c, %c
  94. // CHECK:STDOUT: %G.ref.loc27: <function> = name_ref G, @Class.%G [template = @Class.%G]
  95. // CHECK:STDOUT: %.loc27_4: <bound method> = bound_method %c.ref.loc27, %G.ref.loc27
  96. // CHECK:STDOUT: %.loc27_6: init () = call %.loc27_4(<invalid>) [template = <error>]
  97. // CHECK:STDOUT: %p.ref.loc30: Class* = name_ref p, %p
  98. // CHECK:STDOUT: %.loc30_4.1: ref Class = deref %p.ref.loc30
  99. // CHECK:STDOUT: %F.ref.loc30: <function> = name_ref F, @Class.%F [template = @Class.%F]
  100. // CHECK:STDOUT: %.loc30_7: <bound method> = bound_method %.loc30_4.1, %F.ref.loc30
  101. // CHECK:STDOUT: %.loc30_4.2: Class* = addr_of %.loc30_4.1
  102. // CHECK:STDOUT: %.loc30_9: init () = call %.loc30_7(%.loc30_4.2)
  103. // CHECK:STDOUT: %p.ref.loc38: Class* = name_ref p, %p
  104. // CHECK:STDOUT: %.loc38_4.1: ref Class = deref %p.ref.loc38
  105. // CHECK:STDOUT: %G.ref.loc38: <function> = name_ref G, @Class.%G [template = @Class.%G]
  106. // CHECK:STDOUT: %.loc38_7: <bound method> = bound_method %.loc38_4.1, %G.ref.loc38
  107. // CHECK:STDOUT: %.loc38_4.2: Class* = addr_of %.loc38_4.1
  108. // CHECK:STDOUT: %.loc38_9: init () = call %.loc38_7(<invalid>) [template = <error>]
  109. // CHECK:STDOUT: return
  110. // CHECK:STDOUT: }
  111. // CHECK:STDOUT: