jakt
jakt copied to clipboard
Presence of create() function produces error of function re-declaration
To reproduce:
class C {
public function create() throws {
return C()
}
}
function main() {
println("{}", C::create())
}
Error message:
error: class member cannot be redeclared
static ErrorOr<NonnullRefPtr<C>> create() { auto o = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) C ())); return o; }
^
build/no-return-type.cpp:7:34: note: previous declaration is here
static ErrorOr<NonnullRefPtr<C>> create();
^
For clarity, there is a workaround:
Re-name the function, for instance to creat()
.
Yes, because create is used as codegened name for the function, at least for classes. It was likely done like this to mimic what is done in serenity in many places where a public create function creates a shared pointer (jakt classes are always shared too) and the constructor is made private. I cannot see any real functional reason. I would suggest reserving double underscore prefix for codegen and codening as __create. @jntrnr @awesomekling ?