bug_multi_impl_scoping.carbon 1.6 KB

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