require_invalid.carbon 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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/none.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/require_invalid.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/facet/require_invalid.carbon
  12. // --- fail_require_outside_scope.carbon
  13. library "[[@TEST_NAME]]";
  14. interface Y {}
  15. // CHECK:STDERR: fail_require_outside_scope.carbon:[[@LINE+4]]:1: error: `require` can only be used in an `interface` or `constraint` [RequireInWrongScope]
  16. // CHECK:STDERR: require impls Y;
  17. // CHECK:STDERR: ^~~~~~~
  18. // CHECK:STDERR:
  19. require impls Y;
  20. // --- fail_require_in_class.carbon
  21. library "[[@TEST_NAME]]";
  22. interface Y {}
  23. class C {
  24. // CHECK:STDERR: fail_require_in_class.carbon:[[@LINE+4]]:3: error: `require` can only be used in an `interface` or `constraint` [RequireInWrongScope]
  25. // CHECK:STDERR: require impls Y;
  26. // CHECK:STDERR: ^~~~~~~
  27. // CHECK:STDERR:
  28. require impls Y;
  29. }
  30. // --- fail_require_in_fn.carbon
  31. library "[[@TEST_NAME]]";
  32. interface Y {}
  33. fn F() {
  34. // require is not allowed outside of `interface` or `constraint`.
  35. //
  36. // CHECK:STDERR: fail_require_in_fn.carbon:[[@LINE+8]]:3: error: expected expression [ExpectedExpr]
  37. // CHECK:STDERR: require impls Y;
  38. // CHECK:STDERR: ^~~~~~~
  39. // CHECK:STDERR:
  40. // CHECK:STDERR: fail_require_in_fn.carbon:[[@LINE+4]]:3: error: semantics TODO: `handle invalid parse trees in `check`` [SemanticsTodo]
  41. // CHECK:STDERR: require impls Y;
  42. // CHECK:STDERR: ^~~~~~~
  43. // CHECK:STDERR:
  44. require impls Y;
  45. }
  46. // --- fail_require_in_nested_class.carbon
  47. library "[[@TEST_NAME]]";
  48. interface Y {}
  49. interface Z {
  50. // TODO: Add `default` modifier.
  51. fn F() {
  52. class C {
  53. // CHECK:STDERR: fail_require_in_nested_class.carbon:[[@LINE+4]]:7: error: `require` can only be used in an `interface` or `constraint` [RequireInWrongScope]
  54. // CHECK:STDERR: require impls Y;
  55. // CHECK:STDERR: ^~~~~~~
  56. // CHECK:STDERR:
  57. require impls Y;
  58. }
  59. }
  60. }
  61. // --- fail_require_in_nested_fn.carbon
  62. library "[[@TEST_NAME]]";
  63. interface Y {}
  64. interface Z {
  65. // TODO: Add `default` modifier.
  66. fn F() {
  67. // require is not allowed outside of `interface` or `constraint`.
  68. //
  69. // CHECK:STDERR: fail_require_in_nested_fn.carbon:[[@LINE+8]]:5: error: expected expression [ExpectedExpr]
  70. // CHECK:STDERR: require impls Y;
  71. // CHECK:STDERR: ^~~~~~~
  72. // CHECK:STDERR:
  73. // CHECK:STDERR: fail_require_in_nested_fn.carbon:[[@LINE+4]]:5: error: semantics TODO: `handle invalid parse trees in `check`` [SemanticsTodo]
  74. // CHECK:STDERR: require impls Y;
  75. // CHECK:STDERR: ^~~~~~~
  76. // CHECK:STDERR:
  77. require impls Y;
  78. }
  79. }
  80. // --- fail_errors_in_require_still_found.carbon
  81. library "[[@TEST_NAME]]";
  82. class C {
  83. // The `require` is diagnosed as being in the wrong place. But we can still
  84. // diagnose issues inside the decl too.
  85. //
  86. // CHECK:STDERR: fail_errors_in_require_still_found.carbon:[[@LINE+8]]:3: error: `require` can only be used in an `interface` or `constraint` [RequireInWrongScope]
  87. // CHECK:STDERR: require impls Y;
  88. // CHECK:STDERR: ^~~~~~~
  89. // CHECK:STDERR:
  90. // CHECK:STDERR: fail_errors_in_require_still_found.carbon:[[@LINE+4]]:17: error: name `Y` not found [NameNotFound]
  91. // CHECK:STDERR: require impls Y;
  92. // CHECK:STDERR: ^
  93. // CHECK:STDERR:
  94. require impls Y;
  95. }
  96. // --- fail_extend_require_type.carbon
  97. library "[[@TEST_NAME]]";
  98. interface Y {}
  99. interface Z {
  100. // CHECK:STDERR: fail_extend_require_type.carbon:[[@LINE+4]]:18: error: `extend require impls` with explicit type [RequireImplsExtendWithExplicitSelf]
  101. // CHECK:STDERR: extend require () impls Y;
  102. // CHECK:STDERR: ^~
  103. // CHECK:STDERR:
  104. extend require () impls Y;
  105. }