bug_multi_impl_scoping.carbon 1.6 KB

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