fail_multi_impl_scoping.carbon 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. // TODO: We should not accept this.
  30. let w: Self.(A.TA) = 3;
  31. return v + w;
  32. }
  33. }
  34. }
  35. external impl C(i32) as B where .TB == () {
  36. fn FB() -> () { return (); }
  37. // CHECK:STDERR: COMPILATION ERROR: {{.*}}/explorer/testdata/assoc_const/fail_multi_impl_scoping.carbon:[[@LINE+1]]: ambiguous implementations of interface B for class C(T = i32)
  38. }
  39. fn Main() -> i32 { return C(i32).FB(); }