fail_adapt_bad_decl.carbon 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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/class/adapter/fail_adapt_bad_decl.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/adapter/fail_adapt_bad_decl.carbon
  12. // --- fail_not_type.carbon
  13. library "[[@TEST_NAME]]";
  14. class Bad {
  15. // CHECK:STDERR: fail_not_type.carbon:[[@LINE+7]]:3: error: cannot implicitly convert non-type value of type `Core.IntLiteral` to `type` [ConversionFailureNonTypeToFacet]
  16. // CHECK:STDERR: adapt 100;
  17. // CHECK:STDERR: ^~~~~~~~~~
  18. // CHECK:STDERR: fail_not_type.carbon:[[@LINE+4]]:3: note: type `Core.IntLiteral` does not implement interface `Core.ImplicitAs(type)` [MissingImplInMemberAccessNote]
  19. // CHECK:STDERR: adapt 100;
  20. // CHECK:STDERR: ^~~~~~~~~~
  21. // CHECK:STDERR:
  22. adapt 100;
  23. }
  24. // CHECK:STDERR: fail_not_type.carbon:[[@LINE+4]]:18: error: member name `F` not found in `Bad` [MemberNameNotFoundInInstScope]
  25. // CHECK:STDERR: fn Use(b: Bad) { b.F(); }
  26. // CHECK:STDERR: ^~~
  27. // CHECK:STDERR:
  28. fn Use(b: Bad) { b.F(); }
  29. // --- fail_extend_not_type.carbon
  30. library "[[@TEST_NAME]]";
  31. class Bad {
  32. // CHECK:STDERR: fail_extend_not_type.carbon:[[@LINE+7]]:3: error: cannot implicitly convert non-type value of type `Core.IntLiteral` to `type` [ConversionFailureNonTypeToFacet]
  33. // CHECK:STDERR: extend adapt 100;
  34. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~
  35. // CHECK:STDERR: fail_extend_not_type.carbon:[[@LINE+4]]:3: note: type `Core.IntLiteral` does not implement interface `Core.ImplicitAs(type)` [MissingImplInMemberAccessNote]
  36. // CHECK:STDERR: extend adapt 100;
  37. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~
  38. // CHECK:STDERR:
  39. extend adapt 100;
  40. }
  41. // No diagnostic here, we don't know what names Bad has.
  42. fn Use(b: Bad) { b.F(); }
  43. // --- fail_repeated.carbon
  44. library "[[@TEST_NAME]]";
  45. class MultipleAdapts {
  46. adapt ();
  47. // CHECK:STDERR: fail_repeated.carbon:[[@LINE+7]]:3: error: multiple `adapt` declarations in class [AdaptDeclRepeated]
  48. // CHECK:STDERR: adapt {};
  49. // CHECK:STDERR: ^~~~~~~~~
  50. // CHECK:STDERR: fail_repeated.carbon:[[@LINE-4]]:3: note: previous `adapt` declaration is here [ClassSpecificDeclPrevious]
  51. // CHECK:STDERR: adapt ();
  52. // CHECK:STDERR: ^~~~~~~~~
  53. // CHECK:STDERR:
  54. adapt {};
  55. }
  56. class MultipleAdaptsSameType {
  57. adapt ();
  58. // CHECK:STDERR: fail_repeated.carbon:[[@LINE+7]]:3: error: multiple `adapt` declarations in class [AdaptDeclRepeated]
  59. // CHECK:STDERR: adapt ();
  60. // CHECK:STDERR: ^~~~~~~~~
  61. // CHECK:STDERR: fail_repeated.carbon:[[@LINE-4]]:3: note: previous `adapt` declaration is here [ClassSpecificDeclPrevious]
  62. // CHECK:STDERR: adapt ();
  63. // CHECK:STDERR: ^~~~~~~~~
  64. // CHECK:STDERR:
  65. adapt ();
  66. }
  67. // --- fail_bad_scope.carbon
  68. library "[[@TEST_NAME]]";
  69. // CHECK:STDERR: fail_bad_scope.carbon:[[@LINE+4]]:1: error: `adapt` declaration outside class [ClassSpecificDeclOutsideClass]
  70. // CHECK:STDERR: adapt {};
  71. // CHECK:STDERR: ^~~~~~~~~
  72. // CHECK:STDERR:
  73. adapt {};
  74. interface I {
  75. // CHECK:STDERR: fail_bad_scope.carbon:[[@LINE+4]]:3: error: `adapt` declaration outside class [ClassSpecificDeclOutsideClass]
  76. // CHECK:STDERR: adapt {};
  77. // CHECK:STDERR: ^~~~~~~~~
  78. // CHECK:STDERR:
  79. adapt {};
  80. }
  81. class C {
  82. interface I {
  83. // CHECK:STDERR: fail_bad_scope.carbon:[[@LINE+4]]:5: error: `adapt` declaration outside class [ClassSpecificDeclOutsideClass]
  84. // CHECK:STDERR: adapt {};
  85. // CHECK:STDERR: ^~~~~~~~~
  86. // CHECK:STDERR:
  87. adapt {};
  88. }
  89. }