-
-
Notifications
You must be signed in to change notification settings - Fork 220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#[class(no_init)]
to explicitly disable constructor
#593
Conversation
Solves the issue where constructors were accidentally disabled due to forgotten #[class(init)], which also broke hot reloading. Not providing #[class(init)] and not overriding init() now causes a compile error.
…ass as "abstract" "Abstract" is Godot terminology; this does not make it an abstract base class.
API docs are being generated and will be shortly available at: https://godot-rust.github.io/docs/gdext/pr-593 |
Is it actually by design that this compiler error is a little bit cryptic? Or is that rather an accidental regression? For me the compiler would currently fail with something like:
I vaguely remembered seeing this PR, which is why I fortunately made the right guess that I had to add |
Do you have a suggestion how to improve errors here? Some options:
|
On another note, I did add a dedicated chapter about constructors just yesterday, which also elaborates That doesn't dismiss the importance of having good error messages, especially since this one can happen accidentally, but it provides additional knowledge. |
Thanks for clarifying! I somehow guessed that at the time this was introduced the message was better, and it had degraded accidentally.
The problem with "must have init" is that it may also be misleading, because it sounds like having an
We could also mention that error there, but it still may be hard for users to discover. |
The error doesn't happen at macro evaluation time, but only when the expanded code is compiled. It is allowed to have neither This all sucks quite a bit, but unfortunately our hope at ever getting proper compile-time introspection (rather than these proc-macro hacks) was shattered by very professional Rust leadership.
Something like this should be possible 👍
There is already a mention of this:
I'd rather not mention the concrete error wording -- it's one more thing that goes out of sync, and it's very unlikely that people find that page in the book when enountering the error. |
For me it simply would have helped, because the error "the trait bound
would have clarified it for me. Perhaps it would also make the error googlable... |
Adds
#[class(no_init)]
, which is now required to disable constructor.This is a breaking change for cases where the constructor was implicitly disabled -- but this didn't work properly anyway, see below.
Forgetting a constructor is no longer possible: if there is no
#[class(init)]
attribute and no overriddeninit()
function, then the library will emit a compile error. In many cases, constructors were accidentally disabled due to forgotten#[class(init)]
, which also broke hot reloading.In addition, the
no_init
key now registers a class properly as non-instantiable (in Godot terms "abstract", which is confusing). This means that you get a helpful error message in the editor in case you callMyClass.new()
from GDScript:Fixes #539.