fail_multi_impl_scoping.carbon 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. // RUN: %{not} %{explorer} %s 2>&1 | \
  6. // RUN: %{FileCheck} --match-full-lines --allow-unused-prefixes=false %s
  7. // RUN: %{not} %{explorer} --parser_debug --trace_file=- %s 2>&1 | \
  8. // RUN: %{FileCheck} --match-full-lines --allow-unused-prefixes %s
  9. // AUTOUPDATE: %{explorer} %s
  10. package ExplorerTest api;
  11. interface A {
  12. let TA:! Type;
  13. fn FA() -> TA;
  14. }
  15. interface B {
  16. let TB:! Type;
  17. fn FB() -> TB;
  18. }
  19. class C(T:! Type) {
  20. impl as A & B where .TA == i32 and .TB == i32 {
  21. fn FA() -> i32 {
  22. // OK, know that TA is i32 here.
  23. let v: Self.(A.TA) = 1;
  24. let w: i32 = v;
  25. return w;
  26. }
  27. fn FB() -> i32 {
  28. // OK, know that TB is i32 here.
  29. let v: Self.(B.TB) = 2;
  30. // TODO: Don't know that TA is i32. It could be specialized.
  31. // We should reject this once we support specialization.
  32. let w: Self.(A.TA) = 3;
  33. return v + w;
  34. }
  35. }
  36. }
  37. external impl C(i32) as B where .TB == () {
  38. fn FB() -> () { return (); }
  39. // CHECK: COMPILATION ERROR: {{.*}}/explorer/testdata/assoc_const/fail_multi_impl_scoping.carbon:[[@LINE+1]]: ambiguous implementations of interface B for class C(T = i32)
  40. }
  41. fn Main() -> i32 { return C(i32).FB(); }