fail_memaccess_category.carbon 5.0 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 A {
  7. fn F[addr self: A*]();
  8. }
  9. class B {
  10. var a: A;
  11. }
  12. fn F(s: {.a: A}, b: B) {
  13. // `s` has only a value representation, so this must be invalid.
  14. // CHECK:STDERR: fail_memaccess_category.carbon:[[@LINE+7]]:8: ERROR: `addr self` method cannot be invoked on a value.
  15. // CHECK:STDERR: s.a.F();
  16. // CHECK:STDERR: ^
  17. // CHECK:STDERR: fail_memaccess_category.carbon:[[@LINE-12]]:13: Initializing `addr self` parameter of method declared here.
  18. // CHECK:STDERR: fn F[addr self: A*]();
  19. // CHECK:STDERR: ^~~~
  20. // CHECK:STDERR:
  21. s.a.F();
  22. // `b` has an object representation for `A`, but this is still invalid for
  23. // consistency.
  24. // CHECK:STDERR: fail_memaccess_category.carbon:[[@LINE+6]]:8: ERROR: `addr self` method cannot be invoked on a value.
  25. // CHECK:STDERR: b.a.F();
  26. // CHECK:STDERR: ^
  27. // CHECK:STDERR: fail_memaccess_category.carbon:[[@LINE-23]]:13: Initializing `addr self` parameter of method declared here.
  28. // CHECK:STDERR: fn F[addr self: A*]();
  29. // CHECK:STDERR: ^~~~
  30. b.a.F();
  31. }
  32. // CHECK:STDOUT: --- fail_memaccess_category.carbon
  33. // CHECK:STDOUT:
  34. // CHECK:STDOUT: constants {
  35. // CHECK:STDOUT: %A: type = class_type @A [template]
  36. // CHECK:STDOUT: %.1: type = ptr_type A [template]
  37. // CHECK:STDOUT: %.2: type = struct_type {} [template]
  38. // CHECK:STDOUT: %B: type = class_type @B [template]
  39. // CHECK:STDOUT: %.3: type = tuple_type () [template]
  40. // CHECK:STDOUT: %.4: type = ptr_type {} [template]
  41. // CHECK:STDOUT: %.5: type = unbound_element_type B, A [template]
  42. // CHECK:STDOUT: %.6: type = struct_type {.a: A} [template]
  43. // CHECK:STDOUT: %.7: type = struct_type {.a: {}*} [template]
  44. // CHECK:STDOUT: %.8: type = ptr_type {.a: A} [template]
  45. // CHECK:STDOUT: }
  46. // CHECK:STDOUT:
  47. // CHECK:STDOUT: file {
  48. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  49. // CHECK:STDOUT: .Core = %Core
  50. // CHECK:STDOUT: .A = %A.decl
  51. // CHECK:STDOUT: .B = %B.decl
  52. // CHECK:STDOUT: .F = %F
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  55. // CHECK:STDOUT: %A.decl: type = class_decl @A [template = constants.%A] {}
  56. // CHECK:STDOUT: %B.decl: type = class_decl @B [template = constants.%B] {}
  57. // CHECK:STDOUT: %F: <function> = fn_decl @F.2 [template] {
  58. // CHECK:STDOUT: %A.ref: type = name_ref A, %A.decl [template = constants.%A]
  59. // CHECK:STDOUT: %.loc15: type = struct_type {.a: A} [template = constants.%.6]
  60. // CHECK:STDOUT: %s.loc15_6.1: {.a: A} = param s
  61. // CHECK:STDOUT: @F.2.%s: {.a: A} = bind_name s, %s.loc15_6.1
  62. // CHECK:STDOUT: %B.ref: type = name_ref B, %B.decl [template = constants.%B]
  63. // CHECK:STDOUT: %b.loc15_18.1: B = param b
  64. // CHECK:STDOUT: @F.2.%b: B = bind_name b, %b.loc15_18.1
  65. // CHECK:STDOUT: }
  66. // CHECK:STDOUT: }
  67. // CHECK:STDOUT:
  68. // CHECK:STDOUT: class @A {
  69. // CHECK:STDOUT: %F: <function> = fn_decl @F.1 [template] {
  70. // CHECK:STDOUT: %A.ref: type = name_ref A, file.%A.decl [template = constants.%A]
  71. // CHECK:STDOUT: %.loc8_20: type = ptr_type A [template = constants.%.1]
  72. // CHECK:STDOUT: %self.loc8_13.1: A* = param self
  73. // CHECK:STDOUT: %self.loc8_13.3: A* = bind_name self, %self.loc8_13.1
  74. // CHECK:STDOUT: %.loc8_8: A* = addr_pattern %self.loc8_13.3
  75. // CHECK:STDOUT: }
  76. // CHECK:STDOUT:
  77. // CHECK:STDOUT: !members:
  78. // CHECK:STDOUT: .Self = constants.%A
  79. // CHECK:STDOUT: .F = %F
  80. // CHECK:STDOUT: }
  81. // CHECK:STDOUT:
  82. // CHECK:STDOUT: class @B {
  83. // CHECK:STDOUT: %A.ref: type = name_ref A, file.%A.decl [template = constants.%A]
  84. // CHECK:STDOUT: %.loc12: <unbound element of class B> = field_decl a, element0 [template]
  85. // CHECK:STDOUT:
  86. // CHECK:STDOUT: !members:
  87. // CHECK:STDOUT: .Self = constants.%B
  88. // CHECK:STDOUT: .a = %.loc12
  89. // CHECK:STDOUT: }
  90. // CHECK:STDOUT:
  91. // CHECK:STDOUT: fn @F.1[addr @A.%self.loc8_13.3: A*]();
  92. // CHECK:STDOUT:
  93. // CHECK:STDOUT: fn @F.2(%s: {.a: A}, %b: B) {
  94. // CHECK:STDOUT: !entry:
  95. // CHECK:STDOUT: %s.ref: {.a: A} = name_ref s, %s
  96. // CHECK:STDOUT: %.loc24_4: A = struct_access %s.ref, element0
  97. // CHECK:STDOUT: %F.ref.loc24: <function> = name_ref F, @A.%F [template = @A.%F]
  98. // CHECK:STDOUT: %.loc24_6: <bound method> = bound_method %.loc24_4, %F.ref.loc24
  99. // CHECK:STDOUT: %.loc24_8: init () = call %.loc24_6(<invalid>) [template = <error>]
  100. // CHECK:STDOUT: %b.ref: B = name_ref b, %b
  101. // CHECK:STDOUT: %a.ref: <unbound element of class B> = name_ref a, @B.%.loc12 [template = @B.%.loc12]
  102. // CHECK:STDOUT: %.loc34_4.1: ref A = class_element_access %b.ref, element0
  103. // CHECK:STDOUT: %.loc34_4.2: A = bind_value %.loc34_4.1
  104. // CHECK:STDOUT: %F.ref.loc34: <function> = name_ref F, @A.%F [template = @A.%F]
  105. // CHECK:STDOUT: %.loc34_6: <bound method> = bound_method %.loc34_4.2, %F.ref.loc34
  106. // CHECK:STDOUT: %.loc34_8: init () = call %.loc34_6(<invalid>) [template = <error>]
  107. // CHECK:STDOUT: return
  108. // CHECK:STDOUT: }
  109. // CHECK:STDOUT: