bug_multi_impl_scoping.carbon 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. package ExplorerTest api;
  7. interface A {
  8. let TA:! type;
  9. fn FA() -> TA;
  10. }
  11. interface B {
  12. let TB:! type;
  13. fn FB() -> TB;
  14. }
  15. class C(T:! type) {
  16. extend impl as A & B where .TA = i32 and .TB = i32 {
  17. fn FA() -> i32 {
  18. Print("(C(T) as A).FA()");
  19. // OK, know that TA is i32 here.
  20. let v: Self.(A.TA) = 1;
  21. let w: i32 = v;
  22. return w;
  23. }
  24. fn FB() -> i32 {
  25. Print("(C(T) as B).FB()");
  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) = Self.(A.FA)();
  31. return v + w;
  32. }
  33. }
  34. }
  35. impl C(i32) as A where .TA = (i32, i32) {
  36. fn FA() -> (i32, i32) {
  37. Print("(C(i32) as A).FA()");
  38. return (6, 7);
  39. }
  40. }
  41. fn Main() -> i32 {
  42. Print("{0}", C(i32).(A.FA)()[0]);
  43. Print("{0}", C(i32).(A.FA)()[1]);
  44. // TODO: The implementation of C(T) as B eagerly picked the (non-final)
  45. // implementation of C(T) as A, so this ends up using a different
  46. // implementation of C(i32) as A than the one we just used, violating
  47. // coherence.
  48. Print("{0}", C(i32).(B.FB)());
  49. return 0;
  50. }
  51. // CHECK:STDOUT: (C(i32) as A).FA()
  52. // CHECK:STDOUT: 6
  53. // CHECK:STDOUT: (C(i32) as A).FA()
  54. // CHECK:STDOUT: 7
  55. // CHECK:STDOUT: (C(T) as B).FB()
  56. // CHECK:STDOUT: (C(T) as A).FA()
  57. // CHECK:STDOUT: 3
  58. // CHECK:STDOUT: result: 0