fail_virtual_method_absent.carbon 703 B

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