Skip to content

Commit ec3f4d3

Browse files
LucasCholletalimpfard
authored andcommitted
cpp_import: Let Jakt know if imported methods are virtual
This allows Jakt classes to override methods defined in C++ classes.
1 parent 8087f6a commit ec3f4d3

3 files changed

Lines changed: 21 additions & 1 deletion

File tree

selfhost/cpp_import/clang.jakt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1741,6 +1741,8 @@ class CppImportProcessor {
17411741
is_method and clang_CXXMethod_isStatic(cursor)
17421742
) or not is_method
17431743

1744+
let is_virtual = clang_CXXMethod_isVirtual(cursor)
1745+
17441746
if not this_type.has_value() and (kind is Constructor or kind is Destructor) {
17451747
if .debug_print { eprintln("[ICE] Constructor or destructor ({}) without a this type", name_from(cursor)) }
17461748
return
@@ -1907,7 +1909,7 @@ class CppImportProcessor {
19071909
is_instantiated: true
19081910
parsed_function: None
19091911
is_comptime: false
1910-
is_virtual: false
1912+
is_virtual: is_virtual
19111913
is_override: false
19121914
is_unsafe: false
19131915
has_varargs
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class Parent {
2+
protected:
3+
virtual void f() { AK::outln("From the parent"); };
4+
};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/// Expect:
2+
/// - output: "From the child\n"
3+
/// - cppincludes: "."
4+
5+
import extern "polymorphism_override_cpp_method.h"
6+
7+
class Child : Parent {
8+
public override fn f(mut this) { print("From the child\n"); }
9+
}
10+
11+
fn main() {
12+
mut c = Child()
13+
c.f()
14+
}

0 commit comments

Comments
 (0)