fail_virtual_method_absent.carbon 614 B

1234567891011121314151617181920212223
  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. // NOAUTOUPDATE
  6. package ExplorerTest api;
  7. base class A {}
  8. class B {
  9. extend base: A;
  10. virtual fn Foo[self: Self]() -> i32 { return 0; }
  11. }
  12. fn Main() -> i32 {
  13. var b: B = { .base = {}};
  14. var bp: B* = &b;
  15. var ap: A* = bp;
  16. // Shouldn't look into the vtable for B.
  17. // CHECK:STDERR: COMPILATION ERROR: fail_virtual_method_absent.carbon:[[@LINE+1]]: class A does not have a field named Foo
  18. return ap->Foo();
  19. }