bevyengine / bevy-website

The source files for the official Bevy website
https://bevyengine.org
MIT License
192 stars 330 forks source link

Document the "no method named `system` found for fn" error #82

Open martindemello opened 3 years ago

martindemello commented 3 years ago

Getting the wrong signature for a function leads to a complex error message like

error[E0599]: no method named `system` found for fn item `for<'r, 's, 't0, 't1, 't2, 't3> fn(&'r mut bevy::prelude::Commands, &'s mut bevy::prelude::ResMut<'t0, GameState>, bevy::prelude::Query<'t1, (&'t2 PieceIndex, &'t3 mut Position), bevy::prelude::With<CurrentPiece>>) {place_current_piece}` in the current scope
   --> src/main.rs:168:41
    |
168 |         .add_system(place_current_piece.system())
    |                                         ^^^^^^ method not found in `for<'r, 's, 't0, 't1, 't2, 't3> fn(&'r mut bevy::prelude::Commands, &'s mut bevy::prelude::ResMut<'t0, GameState>, bevy::prelude::Query<'t1, (&'t2 PieceIndex, &'t3 mut Position), bevy::prelude::With<CurrentPiece>>) {place_current_piece}`
    |
    = note: `place_current_piece` is a function, perhaps you wish to call it

I managed to solve my issue thanks to this reddit comment (specifically I had the arg state: &mut ResMut<GameState> where bevy wanted mut state: ResMut<GameState>), but that was literally the only helpful documentation I could find.

The error and a set of guidelines for what an acceptable fn signature is should be documented somewhere in the bevy book, perhaps in the Troubleshooting section to begin with.

concave-sphere commented 3 years ago

This was one of the issues I ran into when learning Bevy, and it's one of the ones that hasn't gone away. I'm better at diagnosing these issues, but it's too easy to accidentally leave off or add a & or mut, and spotting the problem always feels like finding a needle in a haystack. I'm porting my code to "pre-0.5" now and it's just the same thing over again with new rules.

Documentation is a good short term fix, but I would suggest looking for technical ways to improve the error message here.

SIGSTACKFAULT commented 3 months ago

still a problem except nowadays the error message is

error[E0277]: the trait bound `for<'a> fn(&'a mut MyResource) {invalid_system}: IntoSystemConfigs<_>` is not satisfied
   --> src/main.rs:8:30
    |
8   |     app.add_systems(Startup, invalid_system);
    |         -----------          ^^^^^^^^^^^^^^ the trait `IntoSystem<(), (), _>` is not implemented for fn item `for<'a> fn(&'a mut MyResource) {invalid_system}`, which is required by `for<'a> fn(&'a mut MyResource) {invalid_system}: IntoSystemConfigs<_>`
    |         |
    |         required by a bound introduced by this call
    |