fail_virtual_method_absent.carbon 628 B

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