fail_assoc_const_not_binding.carbon 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. // TODO: Add ranges and switch to "--dump-sem-ir-ranges=only".
  6. // EXTRA-ARGS: --no-prelude-import --dump-sem-ir-ranges=if-present
  7. //
  8. // AUTOUPDATE
  9. // TIP: To test this file alone, run:
  10. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interface/fail_assoc_const_not_binding.carbon
  11. // TIP: To dump output, run:
  12. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interface/fail_assoc_const_not_binding.carbon
  13. // --- fail_tuple_pattern.carbon
  14. library "[[@TEST_NAME]]";
  15. interface I {
  16. // CHECK:STDERR: fail_tuple_pattern.carbon:[[@LINE+4]]:7: error: found tuple pattern in associated constant declaration; expected symbolic binding pattern [ExpectedSingleBindingInAssociatedConstant]
  17. // CHECK:STDERR: let (T:! type, U:! type);
  18. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~
  19. // CHECK:STDERR:
  20. let (T:! type, U:! type);
  21. }
  22. // --- fail_tuple_pattern_with_default.carbon
  23. library "[[@TEST_NAME]]";
  24. interface I {
  25. // CHECK:STDERR: fail_tuple_pattern_with_default.carbon:[[@LINE+4]]:15: error: found tuple pattern in associated constant declaration; expected symbolic binding pattern [ExpectedSingleBindingInAssociatedConstant]
  26. // CHECK:STDERR: default let (T:! type, U:! type) = ({}, {});
  27. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~
  28. // CHECK:STDERR:
  29. default let (T:! type, U:! type) = ({}, {});
  30. }
  31. // --- fail_var_pattern.carbon
  32. library "[[@TEST_NAME]]";
  33. interface I {
  34. // CHECK:STDERR: fail_var_pattern.carbon:[[@LINE+8]]:11: error: semantics TODO: `handle invalid parse trees in `check`` [SemanticsTodo]
  35. // CHECK:STDERR: let var T:! type;
  36. // CHECK:STDERR: ^~~~~~~~
  37. // CHECK:STDERR:
  38. // CHECK:STDERR: fail_var_pattern.carbon:[[@LINE+4]]:19: error: `var` pattern cannot declare a compile-time binding [CompileTimeBindingInVarDecl]
  39. // CHECK:STDERR: let var T:! type;
  40. // CHECK:STDERR: ^
  41. // CHECK:STDERR:
  42. let var T:! type;
  43. }
  44. // --- fail_var_pattern_with_default.carbon
  45. library "[[@TEST_NAME]]";
  46. interface I {
  47. // CHECK:STDERR: fail_var_pattern_with_default.carbon:[[@LINE+8]]:19: error: semantics TODO: `handle invalid parse trees in `check`` [SemanticsTodo]
  48. // CHECK:STDERR: default let var T:! type = {};
  49. // CHECK:STDERR: ^~~~~~~~
  50. // CHECK:STDERR:
  51. // CHECK:STDERR: fail_var_pattern_with_default.carbon:[[@LINE+4]]:28: error: `var` pattern cannot declare a compile-time binding [CompileTimeBindingInVarDecl]
  52. // CHECK:STDERR: default let var T:! type = {};
  53. // CHECK:STDERR: ^
  54. // CHECK:STDERR:
  55. default let var T:! type = {};
  56. }
  57. // CHECK:STDOUT: --- fail_tuple_pattern.carbon
  58. // CHECK:STDOUT:
  59. // CHECK:STDOUT: constants {
  60. // CHECK:STDOUT: %I.type: type = facet_type <@I> [concrete]
  61. // CHECK:STDOUT: %Self: %I.type = bind_symbolic_name Self, 0 [symbolic]
  62. // CHECK:STDOUT: }
  63. // CHECK:STDOUT:
  64. // CHECK:STDOUT: file {
  65. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  66. // CHECK:STDOUT: .I = %I.decl
  67. // CHECK:STDOUT: }
  68. // CHECK:STDOUT: %I.decl: type = interface_decl @I [concrete = constants.%I.type] {} {}
  69. // CHECK:STDOUT: }
  70. // CHECK:STDOUT:
  71. // CHECK:STDOUT: interface @I {
  72. // CHECK:STDOUT: %Self: %I.type = bind_symbolic_name Self, 0 [symbolic = constants.%Self]
  73. // CHECK:STDOUT:
  74. // CHECK:STDOUT: !members:
  75. // CHECK:STDOUT: .Self = %Self
  76. // CHECK:STDOUT: has_error
  77. // CHECK:STDOUT: witness = ()
  78. // CHECK:STDOUT: }
  79. // CHECK:STDOUT:
  80. // CHECK:STDOUT: assoc_const @T T:! type;
  81. // CHECK:STDOUT:
  82. // CHECK:STDOUT: assoc_const @U U:! type;
  83. // CHECK:STDOUT:
  84. // CHECK:STDOUT: --- fail_tuple_pattern_with_default.carbon
  85. // CHECK:STDOUT:
  86. // CHECK:STDOUT: constants {
  87. // CHECK:STDOUT: %I.type: type = facet_type <@I> [concrete]
  88. // CHECK:STDOUT: %Self: %I.type = bind_symbolic_name Self, 0 [symbolic]
  89. // CHECK:STDOUT: }
  90. // CHECK:STDOUT:
  91. // CHECK:STDOUT: file {
  92. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  93. // CHECK:STDOUT: .I = %I.decl
  94. // CHECK:STDOUT: }
  95. // CHECK:STDOUT: %I.decl: type = interface_decl @I [concrete = constants.%I.type] {} {}
  96. // CHECK:STDOUT: }
  97. // CHECK:STDOUT:
  98. // CHECK:STDOUT: interface @I {
  99. // CHECK:STDOUT: %Self: %I.type = bind_symbolic_name Self, 0 [symbolic = constants.%Self]
  100. // CHECK:STDOUT:
  101. // CHECK:STDOUT: !members:
  102. // CHECK:STDOUT: .Self = %Self
  103. // CHECK:STDOUT: has_error
  104. // CHECK:STDOUT: witness = ()
  105. // CHECK:STDOUT: }
  106. // CHECK:STDOUT:
  107. // CHECK:STDOUT: assoc_const @T T:! type;
  108. // CHECK:STDOUT:
  109. // CHECK:STDOUT: assoc_const @U U:! type;
  110. // CHECK:STDOUT:
  111. // CHECK:STDOUT: --- fail_var_pattern.carbon
  112. // CHECK:STDOUT:
  113. // CHECK:STDOUT: constants {
  114. // CHECK:STDOUT: }
  115. // CHECK:STDOUT:
  116. // CHECK:STDOUT: interface @I {
  117. // CHECK:STDOUT: !members:
  118. // CHECK:STDOUT: .Self = <unexpected>.inst17
  119. // CHECK:STDOUT: witness = invalid
  120. // CHECK:STDOUT: }
  121. // CHECK:STDOUT:
  122. // CHECK:STDOUT: --- fail_var_pattern_with_default.carbon
  123. // CHECK:STDOUT:
  124. // CHECK:STDOUT: constants {
  125. // CHECK:STDOUT: }
  126. // CHECK:STDOUT:
  127. // CHECK:STDOUT: interface @I {
  128. // CHECK:STDOUT: !members:
  129. // CHECK:STDOUT: .Self = <unexpected>.inst17
  130. // CHECK:STDOUT: witness = invalid
  131. // CHECK:STDOUT: }
  132. // CHECK:STDOUT: