runtime_value.carbon 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. // CHECK:STDERR: fail_member_lookup_in_runtime_facet_without_value.carbon:[[@LINE+4]]:15: error: cannot evaluate type expression [TypeExprEvaluationFailure]
  62. // CHECK:STDERR: fn F(T: Z, v: T.X);
  63. // CHECK:STDERR: ^~~
  64. // CHECK:STDERR:
  65. fn F(T: Z, v: T.X);
  66. // --- fail_todo_compound_member_lookup_in_runtime_facet_with_value.carbon
  67. library "[[@TEST_NAME]]";
  68. interface Z {
  69. let X:! type;
  70. }
  71. // TODO: We should be able to get the value of `.X` from the `FacetType` of
  72. // `T`.
  73. //
  74. // 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]
  75. // CHECK:STDERR: fn F(T: Z where .X = (), v: T.(Z.X));
  76. // CHECK:STDERR: ^~~~~~~
  77. // CHECK:STDERR:
  78. fn F(T: Z where .X = (), v: T.(Z.X));
  79. // --- fail_todo_member_lookup_in_runtime_facet_with_value.carbon
  80. library "[[@TEST_NAME]]";
  81. interface Z {
  82. let X:! type;
  83. }
  84. // TODO: We should be able to get the value of `.X` from the `FacetType` of
  85. // `T`.
  86. //
  87. // CHECK:STDERR: fail_todo_member_lookup_in_runtime_facet_with_value.carbon:[[@LINE+4]]:29: error: cannot evaluate type expression [TypeExprEvaluationFailure]
  88. // CHECK:STDERR: fn F(T: Z where .X = (), v: T.X);
  89. // CHECK:STDERR: ^~~
  90. // CHECK:STDERR:
  91. fn F(T: Z where .X = (), v: T.X);
  92. // CHECK:STDOUT: --- facet_value_copy_from_reference.carbon
  93. // CHECK:STDOUT:
  94. // CHECK:STDOUT: constants {
  95. // CHECK:STDOUT: %I.type: type = facet_type <@I> [concrete]
  96. // CHECK:STDOUT: %C: type = class_type @C [concrete]
  97. // CHECK:STDOUT: %C.elem: type = unbound_element_type %C, %I.type [concrete]
  98. // CHECK:STDOUT: %pattern_type.09a: type = pattern_type %I.type [concrete]
  99. // CHECK:STDOUT: }
  100. // CHECK:STDOUT:
  101. // CHECK:STDOUT: imports {
  102. // CHECK:STDOUT: }
  103. // CHECK:STDOUT:
  104. // CHECK:STDOUT: fn @F(%c.param: %C) {
  105. // CHECK:STDOUT: !entry:
  106. // CHECK:STDOUT: name_binding_decl {
  107. // CHECK:STDOUT: %a.patt: %pattern_type.09a = binding_pattern a [concrete]
  108. // CHECK:STDOUT: }
  109. // CHECK:STDOUT: %c.ref: %C = name_ref c, %c
  110. // CHECK:STDOUT: %i.ref: %C.elem = name_ref i, @C.%.loc6 [concrete = @C.%.loc6]
  111. // CHECK:STDOUT: %.loc13_15.1: ref %I.type = class_element_access %c.ref, element0
  112. // CHECK:STDOUT: %.loc13_15.2: %I.type = bind_value %.loc13_15.1
  113. // CHECK:STDOUT: %I.ref: type = name_ref I, file.%I.decl [concrete = constants.%I.type]
  114. // CHECK:STDOUT: %a: %I.type = bind_name a, %.loc13_15.2
  115. // CHECK:STDOUT: <elided>
  116. // CHECK:STDOUT: }
  117. // CHECK:STDOUT:
  118. // CHECK:STDOUT: --- fail_todo_facet_copy_narrowing_from_reference.carbon
  119. // CHECK:STDOUT:
  120. // CHECK:STDOUT: constants {
  121. // CHECK:STDOUT: %I.type: type = facet_type <@I> [concrete]
  122. // CHECK:STDOUT: %C: type = class_type @C [concrete]
  123. // CHECK:STDOUT: %facet_type: type = facet_type <@I & @J> [concrete]
  124. // CHECK:STDOUT: %C.elem: type = unbound_element_type %C, %facet_type [concrete]
  125. // CHECK:STDOUT: %pattern_type.09a: type = pattern_type %I.type [concrete]
  126. // CHECK:STDOUT: }
  127. // CHECK:STDOUT:
  128. // CHECK:STDOUT: imports {
  129. // CHECK:STDOUT: }
  130. // CHECK:STDOUT:
  131. // CHECK:STDOUT: fn @F(%c.param: %C) {
  132. // CHECK:STDOUT: !entry:
  133. // CHECK:STDOUT: name_binding_decl {
  134. // CHECK:STDOUT: %a.patt: %pattern_type.09a = binding_pattern a [concrete]
  135. // CHECK:STDOUT: }
  136. // CHECK:STDOUT: %c.ref: %C = name_ref c, %c
  137. // CHECK:STDOUT: %ij.ref: %C.elem = name_ref ij, @C.%.loc7_9 [concrete = @C.%.loc7_9]
  138. // CHECK:STDOUT: %.loc21_15.1: ref %facet_type = class_element_access %c.ref, element0
  139. // CHECK:STDOUT: %.loc21_15.2: %facet_type = bind_value %.loc21_15.1
  140. // CHECK:STDOUT: %I.ref: type = name_ref I, file.%I.decl [concrete = constants.%I.type]
  141. // CHECK:STDOUT: %a: %I.type = bind_name a, <error> [concrete = <error>]
  142. // CHECK:STDOUT: <elided>
  143. // CHECK:STDOUT: }
  144. // CHECK:STDOUT: