fail_impl_as_member_access.carbon 718 B

1234567891011121314151617181920212223242526
  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 HasFoo {
  10. fn Foo();
  11. }
  12. constraint ImplAsHasFoo {
  13. impl as HasFoo;
  14. }
  15. fn CallFoo[T:! ImplAsHasFoo](x: T) {
  16. // OK, T is HasFoo.
  17. x.(HasFoo.Foo)();
  18. // CHECK:STDERR: COMPILATION ERROR: {{.*}}/explorer/testdata/named_constraint/fail_impl_as_member_access.carbon:[[@LINE+1]]: member access, Foo not in constraint ImplAsHasFoo where T impls interface HasFoo
  19. x.Foo();
  20. }
  21. fn Main() -> i32 { return 0; }