fail_multi_impl_scoping.carbon 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. // AUTOUPDATE
  6. // RUN: %{not} %{explorer-run}
  7. // RUN: %{not} %{explorer-run-trace}
  8. package ExplorerTest api;
  9. interface A {
  10. let TA:! Type;
  11. fn FA() -> TA;
  12. }
  13. interface B {
  14. let TB:! Type;
  15. fn FB() -> TB;
  16. }
  17. class C(T:! Type) {
  18. impl as A & B where .TA == i32 and .TB == i32 {
  19. fn FA() -> i32 {
  20. // OK, know that TA is i32 here.
  21. let v: Self.(A.TA) = 1;
  22. let w: i32 = v;
  23. return w;
  24. }
  25. fn FB() -> i32 {
  26. // OK, know that TB is i32 here.
  27. let v: Self.(B.TB) = 2;
  28. // Don't know that TA is i32; it could be specialized.
  29. let w: Self.(A.TA) = 3;
  30. // TODO: This error is confusing. We should be diagnosing the previous
  31. // line because we don't know that `3` can be converted to `Self.(A.TA)`.
  32. // CHECK:STDERR: COMPILATION ERROR: {{.*}}/explorer/testdata/assoc_const/fail_multi_impl_scoping.carbon:[[@LINE+1]]: type error in return value: '((class C(T = T)).TB).Result' is not implicitly convertible to 'i32'
  33. return v + w;
  34. }
  35. }
  36. }
  37. external impl C(i32) as B where .TB == () {
  38. fn FB() -> () { return (); }
  39. }
  40. fn Main() -> i32 { return C(i32).FB(); }