runtime_value.carbon 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/convert.carbon
  6. //
  7. // AUTOUPDATE
  8. // TIP: To test this file alone, run:
  9. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/facet/runtime_value.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/facet/runtime_value.carbon
  12. // --- facet_value_copy_from_reference.carbon
  13. library "[[@TEST_NAME]]";
  14. interface I {}
  15. class C {
  16. var i: I;
  17. }
  18. fn F(c: C) {
  19. // Member access produces a reference, which is copied into the value
  20. // binding.
  21. //@dump-sem-ir-begin
  22. let a: I = c.i;
  23. //@dump-sem-ir-end
  24. }
  25. // --- fail_todo_facet_copy_narrowing_from_reference.carbon
  26. library "[[@TEST_NAME]]";
  27. interface I {}
  28. interface J {}
  29. class C {
  30. var ij: I & J;
  31. }
  32. fn F(c: C) {
  33. // Member access produces a reference, which is copied into the value
  34. // binding.
  35. //
  36. // TODO: This copy should work, but the narrowing prevents it currently.
  37. //
  38. //@dump-sem-ir-begin
  39. // CHECK:STDERR: fail_todo_facet_copy_narrowing_from_reference.carbon:[[@LINE+4]]:14: error: semantics TODO: `conversion of runtime facet value` [SemanticsTodo]
  40. // CHECK:STDERR: let a: I = c.ij;
  41. // CHECK:STDERR: ^~~~
  42. // CHECK:STDERR:
  43. let a: I = c.ij;
  44. //@dump-sem-ir-end
  45. }
  46. // --- fail_compound_member_lookup_in_runtime_facet_without_value.carbon
  47. library "[[@TEST_NAME]]";
  48. interface Z {
  49. let X:! type;
  50. }
  51. // CHECK:STDERR: fail_compound_member_lookup_in_runtime_facet_without_value.carbon:[[@LINE+4]]:15: error: semantics TODO: `associated value lookup on runtime facet value` [SemanticsTodo]
  52. // CHECK:STDERR: fn F(T: Z, v: T.(Z.X));
  53. // CHECK:STDERR: ^~~~~~~
  54. // CHECK:STDERR:
  55. fn F(T: Z, v: T.(Z.X));
  56. // --- fail_member_lookup_in_runtime_facet_without_value.carbon
  57. library "[[@TEST_NAME]]";
  58. interface Z {
  59. let X:! type;
  60. }
  61. // TODO: Improve this diagnostic. The problem is that T is a runtime facet
  62. // _and_ its facet type doesn't specific a value for `.X`. Or make this work
  63. // by producing an ImplWitnessAccess that functions against a runtime facet.
  64. //
  65. // CHECK:STDERR: fail_member_lookup_in_runtime_facet_without_value.carbon:[[@LINE+4]]:15: error: cannot access member of interface `Z` in type `Z` that does not implement that interface [MissingImplInMemberAccess]
  66. // CHECK:STDERR: fn F(T: Z, v: T.X);
  67. // CHECK:STDERR: ^~~
  68. // CHECK:STDERR:
  69. fn F(T: Z, v: T.X);
  70. // --- fail_todo_compound_member_lookup_in_runtime_facet_with_value.carbon
  71. library "[[@TEST_NAME]]";
  72. interface Z {
  73. let X:! type;
  74. }
  75. // TODO: We should be able to get the value of `.X` from the `FacetType` of
  76. // `T`.
  77. //
  78. // CHECK:STDERR: fail_todo_compound_member_lookup_in_runtime_facet_with_value.carbon:[[@LINE+4]]:29: error: semantics TODO: `conversion of runtime facet value` [SemanticsTodo]
  79. // CHECK:STDERR: fn F(T: Z where .X = (), v: T.(Z.X));
  80. // CHECK:STDERR: ^~~~~~~
  81. // CHECK:STDERR:
  82. fn F(T: Z where .X = (), v: T.(Z.X));
  83. // --- fail_todo_member_lookup_in_runtime_facet_with_value.carbon
  84. library "[[@TEST_NAME]]";
  85. interface Z {
  86. let X:! type;
  87. }
  88. // TODO: We should be able to get the value of `.X` from the `FacetType` of
  89. // `T`.
  90. //
  91. // CHECK:STDERR: fail_todo_member_lookup_in_runtime_facet_with_value.carbon:[[@LINE+4]]:29: error: cannot access member of interface `Z` in type `Z where .(Z.X) = ()` that does not implement that interface [MissingImplInMemberAccess]
  92. // CHECK:STDERR: fn F(T: Z where .X = (), v: T.X);
  93. // CHECK:STDERR: ^~~
  94. // CHECK:STDERR:
  95. fn F(T: Z where .X = (), v: T.X);
  96. // --- fail_todo_member_lookup_in_type_of_runtime_facet_with_value.carbon
  97. library "[[@TEST_NAME]]";
  98. interface Z {
  99. fn G();
  100. }
  101. fn F(T: Z) {
  102. // CHECK:STDERR: fail_todo_member_lookup_in_type_of_runtime_facet_with_value.carbon:[[@LINE+4]]:3: error: cannot access member of interface `Z` in type `Z` that does not implement that interface [MissingImplInMemberAccess]
  103. // CHECK:STDERR: T.G();
  104. // CHECK:STDERR: ^~~
  105. // CHECK:STDERR:
  106. T.G();
  107. }
  108. // CHECK:STDOUT: --- facet_value_copy_from_reference.carbon
  109. // CHECK:STDOUT:
  110. // CHECK:STDOUT: constants {
  111. // CHECK:STDOUT: %I.type: type = facet_type <@I> [concrete]
  112. // CHECK:STDOUT: %C: type = class_type @C [concrete]
  113. // CHECK:STDOUT: %C.elem: type = unbound_element_type %C, %I.type [concrete]
  114. // CHECK:STDOUT: %pattern_type.9d9: type = pattern_type %I.type [concrete]
  115. // CHECK:STDOUT: }
  116. // CHECK:STDOUT:
  117. // CHECK:STDOUT: imports {
  118. // CHECK:STDOUT: }
  119. // CHECK:STDOUT:
  120. // CHECK:STDOUT: fn @F(%c.param: %C) {
  121. // CHECK:STDOUT: !entry:
  122. // CHECK:STDOUT: name_binding_decl {
  123. // CHECK:STDOUT: %a.patt: %pattern_type.9d9 = value_binding_pattern a [concrete]
  124. // CHECK:STDOUT: }
  125. // CHECK:STDOUT: %c.ref: %C = name_ref c, %c
  126. // CHECK:STDOUT: %i.ref: %C.elem = name_ref i, @C.%.loc6 [concrete = @C.%.loc6]
  127. // CHECK:STDOUT: %.loc13_15.1: ref %I.type = class_element_access %c.ref, element0
  128. // CHECK:STDOUT: %.loc13_15.2: %I.type = acquire_value %.loc13_15.1
  129. // CHECK:STDOUT: %I.ref: type = name_ref I, file.%I.decl [concrete = constants.%I.type]
  130. // CHECK:STDOUT: %a: %I.type = value_binding a, %.loc13_15.2
  131. // CHECK:STDOUT: <elided>
  132. // CHECK:STDOUT: }
  133. // CHECK:STDOUT:
  134. // CHECK:STDOUT: --- fail_todo_facet_copy_narrowing_from_reference.carbon
  135. // CHECK:STDOUT:
  136. // CHECK:STDOUT: constants {
  137. // CHECK:STDOUT: %I.type: type = facet_type <@I> [concrete]
  138. // CHECK:STDOUT: %C: type = class_type @C [concrete]
  139. // CHECK:STDOUT: %facet_type: type = facet_type <@I & @J> [concrete]
  140. // CHECK:STDOUT: %C.elem: type = unbound_element_type %C, %facet_type [concrete]
  141. // CHECK:STDOUT: %pattern_type.9d9: type = pattern_type %I.type [concrete]
  142. // CHECK:STDOUT: }
  143. // CHECK:STDOUT:
  144. // CHECK:STDOUT: imports {
  145. // CHECK:STDOUT: }
  146. // CHECK:STDOUT:
  147. // CHECK:STDOUT: fn @F(%c.param: %C) {
  148. // CHECK:STDOUT: !entry:
  149. // CHECK:STDOUT: name_binding_decl {
  150. // CHECK:STDOUT: %a.patt: %pattern_type.9d9 = value_binding_pattern a [concrete]
  151. // CHECK:STDOUT: }
  152. // CHECK:STDOUT: %c.ref: %C = name_ref c, %c
  153. // CHECK:STDOUT: %ij.ref: %C.elem = name_ref ij, @C.%.loc7_9 [concrete = @C.%.loc7_9]
  154. // CHECK:STDOUT: %.loc21_15.1: ref %facet_type = class_element_access %c.ref, element0
  155. // CHECK:STDOUT: %.loc21_15.2: %facet_type = acquire_value %.loc21_15.1
  156. // CHECK:STDOUT: %I.ref: type = name_ref I, file.%I.decl [concrete = constants.%I.type]
  157. // CHECK:STDOUT: %a: %I.type = value_binding a, <error> [concrete = <error>]
  158. // CHECK:STDOUT: <elided>
  159. // CHECK:STDOUT: }
  160. // CHECK:STDOUT: