import_error.carbon 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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/impl/lookup/import_error.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/impl/lookup/import_error.carbon
  12. // --- fail_error_interface_z.carbon
  13. library "[[@TEST_NAME]]";
  14. interface Z {
  15. let X:! type;
  16. }
  17. // The value of .X is an error.
  18. // CHECK:STDERR: fail_error_interface_z.carbon:[[@LINE+4]]:35: error: associated constant `.(Z.X)` given two different values `{}` and `()` [AssociatedConstantWithDifferentValues]
  19. // CHECK:STDERR: final impl forall [T:! type] T as Z where .X = {} and .X = () {}
  20. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~
  21. // CHECK:STDERR:
  22. final impl forall [T:! type] T as Z where .X = {} and .X = () {}
  23. // --- fail_import_error.carbon
  24. library "[[@TEST_NAME]]";
  25. import library "error_interface_z";
  26. fn F[U:! type](T:! Z) {
  27. // The value of `.X` is an error. It should not crash though.
  28. //
  29. // CHECK:STDERR: fail_import_error.carbon:[[@LINE+7]]:16: error: cannot implicitly convert expression of type `()` to `T.(Z.X)` [ConversionFailure]
  30. // CHECK:STDERR: let a: T.X = ();
  31. // CHECK:STDERR: ^~
  32. // CHECK:STDERR: fail_import_error.carbon:[[@LINE+4]]:16: note: type `()` does not implement interface `Core.ImplicitAs(T.(Z.X))` [MissingImplInMemberAccessNote]
  33. // CHECK:STDERR: let a: T.X = ();
  34. // CHECK:STDERR: ^~
  35. // CHECK:STDERR:
  36. let a: T.X = ();
  37. }