adapt.carbon 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. // --- basic.carbon
  7. library "basic" api;
  8. class SomeClass {
  9. var a: i32;
  10. var b: i32;
  11. }
  12. class SomeClassAdapter {
  13. adapt SomeClass;
  14. }
  15. class StructAdapter {
  16. adapt {.a: i32, .b: i32};
  17. }
  18. // --- fail_not_extend.carbon
  19. library "fail_not_extend" api;
  20. class Adapted {
  21. fn F();
  22. }
  23. class AdaptNotExtend {
  24. adapt Adapted;
  25. }
  26. fn F(a: AdaptNotExtend) {
  27. // `Adapted` is not extended, so lookup for `F` finds nothing.
  28. // CHECK:STDERR: fail_not_extend.carbon:[[@LINE+3]]:3: ERROR: Name `F` not found.
  29. // CHECK:STDERR: a.F();
  30. // CHECK:STDERR: ^~~
  31. a.F();
  32. }
  33. // CHECK:STDOUT: --- basic.carbon
  34. // CHECK:STDOUT:
  35. // CHECK:STDOUT: constants {
  36. // CHECK:STDOUT: %SomeClass: type = class_type @SomeClass [template]
  37. // CHECK:STDOUT: %.1: type = unbound_element_type SomeClass, i32 [template]
  38. // CHECK:STDOUT: %.2: type = struct_type {.a: i32, .b: i32} [template]
  39. // CHECK:STDOUT: %SomeClassAdapter: type = class_type @SomeClassAdapter [template]
  40. // CHECK:STDOUT: %.3: type = ptr_type {.a: i32, .b: i32} [template]
  41. // CHECK:STDOUT: %StructAdapter: type = class_type @StructAdapter [template]
  42. // CHECK:STDOUT: }
  43. // CHECK:STDOUT:
  44. // CHECK:STDOUT: file {
  45. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  46. // CHECK:STDOUT: .Core = %Core
  47. // CHECK:STDOUT: .SomeClass = %SomeClass.decl
  48. // CHECK:STDOUT: .SomeClassAdapter = %SomeClassAdapter.decl
  49. // CHECK:STDOUT: .StructAdapter = %StructAdapter.decl
  50. // CHECK:STDOUT: }
  51. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  52. // CHECK:STDOUT: %SomeClass.decl: type = class_decl @SomeClass [template = constants.%SomeClass] {}
  53. // CHECK:STDOUT: %SomeClassAdapter.decl: type = class_decl @SomeClassAdapter [template = constants.%SomeClassAdapter] {}
  54. // CHECK:STDOUT: %StructAdapter.decl: type = class_decl @StructAdapter [template = constants.%StructAdapter] {}
  55. // CHECK:STDOUT: }
  56. // CHECK:STDOUT:
  57. // CHECK:STDOUT: class @SomeClass {
  58. // CHECK:STDOUT: %.loc5: <unbound element of class SomeClass> = field_decl a, element0 [template]
  59. // CHECK:STDOUT: %.loc6: <unbound element of class SomeClass> = field_decl b, element1 [template]
  60. // CHECK:STDOUT:
  61. // CHECK:STDOUT: !members:
  62. // CHECK:STDOUT: .Self = constants.%SomeClass
  63. // CHECK:STDOUT: .a = %.loc5
  64. // CHECK:STDOUT: .b = %.loc6
  65. // CHECK:STDOUT: }
  66. // CHECK:STDOUT:
  67. // CHECK:STDOUT: class @SomeClassAdapter {
  68. // CHECK:STDOUT: %SomeClass.ref: type = name_ref SomeClass, file.%SomeClass.decl [template = constants.%SomeClass]
  69. // CHECK:STDOUT: adapt_decl SomeClass
  70. // CHECK:STDOUT:
  71. // CHECK:STDOUT: !members:
  72. // CHECK:STDOUT: .Self = constants.%SomeClassAdapter
  73. // CHECK:STDOUT: }
  74. // CHECK:STDOUT:
  75. // CHECK:STDOUT: class @StructAdapter {
  76. // CHECK:STDOUT: %.loc14: type = struct_type {.a: i32, .b: i32} [template = constants.%.2]
  77. // CHECK:STDOUT: adapt_decl {.a: i32, .b: i32}
  78. // CHECK:STDOUT:
  79. // CHECK:STDOUT: !members:
  80. // CHECK:STDOUT: .Self = constants.%StructAdapter
  81. // CHECK:STDOUT: }
  82. // CHECK:STDOUT:
  83. // CHECK:STDOUT: --- fail_not_extend.carbon
  84. // CHECK:STDOUT:
  85. // CHECK:STDOUT: constants {
  86. // CHECK:STDOUT: %Adapted: type = class_type @Adapted [template]
  87. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  88. // CHECK:STDOUT: %AdaptNotExtend: type = class_type @AdaptNotExtend [template]
  89. // CHECK:STDOUT: %.2: type = tuple_type () [template]
  90. // CHECK:STDOUT: %.3: type = ptr_type {} [template]
  91. // CHECK:STDOUT: %.4: type = ptr_type Adapted [template]
  92. // CHECK:STDOUT: }
  93. // CHECK:STDOUT:
  94. // CHECK:STDOUT: file {
  95. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  96. // CHECK:STDOUT: .Core = %Core
  97. // CHECK:STDOUT: .Adapted = %Adapted.decl
  98. // CHECK:STDOUT: .AdaptNotExtend = %AdaptNotExtend.decl
  99. // CHECK:STDOUT: .F = %F
  100. // CHECK:STDOUT: }
  101. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  102. // CHECK:STDOUT: %Adapted.decl: type = class_decl @Adapted [template = constants.%Adapted] {}
  103. // CHECK:STDOUT: %AdaptNotExtend.decl: type = class_decl @AdaptNotExtend [template = constants.%AdaptNotExtend] {}
  104. // CHECK:STDOUT: %F: <function> = fn_decl @F.2 [template] {
  105. // CHECK:STDOUT: %AdaptNotExtend.ref: type = name_ref AdaptNotExtend, %AdaptNotExtend.decl [template = constants.%AdaptNotExtend]
  106. // CHECK:STDOUT: %a.loc12_6.1: AdaptNotExtend = param a
  107. // CHECK:STDOUT: @F.2.%a: AdaptNotExtend = bind_name a, %a.loc12_6.1
  108. // CHECK:STDOUT: }
  109. // CHECK:STDOUT: }
  110. // CHECK:STDOUT:
  111. // CHECK:STDOUT: class @Adapted {
  112. // CHECK:STDOUT: %F: <function> = fn_decl @F.1 [template] {}
  113. // CHECK:STDOUT:
  114. // CHECK:STDOUT: !members:
  115. // CHECK:STDOUT: .Self = constants.%Adapted
  116. // CHECK:STDOUT: .F = %F
  117. // CHECK:STDOUT: }
  118. // CHECK:STDOUT:
  119. // CHECK:STDOUT: class @AdaptNotExtend {
  120. // CHECK:STDOUT: %Adapted.ref: type = name_ref Adapted, file.%Adapted.decl [template = constants.%Adapted]
  121. // CHECK:STDOUT: adapt_decl Adapted
  122. // CHECK:STDOUT:
  123. // CHECK:STDOUT: !members:
  124. // CHECK:STDOUT: .Self = constants.%AdaptNotExtend
  125. // CHECK:STDOUT: }
  126. // CHECK:STDOUT:
  127. // CHECK:STDOUT: fn @F.1();
  128. // CHECK:STDOUT:
  129. // CHECK:STDOUT: fn @F.2(%a: AdaptNotExtend) {
  130. // CHECK:STDOUT: !entry:
  131. // CHECK:STDOUT: %a.ref: AdaptNotExtend = name_ref a, %a
  132. // CHECK:STDOUT: %F.ref: <error> = name_ref F, <error> [template = <error>]
  133. // CHECK:STDOUT: return
  134. // CHECK:STDOUT: }
  135. // CHECK:STDOUT: