Skip to content

Having more than two types param in a type and deriving Reflect errors #18606

@pro470

Description

@pro470

Bevy version

0.15.3

What you did

I get from this code snippet

use super::ScriptFunctionChecker;
use bevy_ecs::system::Resource;
use bevy_mod_scripting::core::event::IntoCallbackLabel;
use bevy_mod_scripting::core::script::ScriptId;
use bevy_mod_scripting::core::IntoScriptPluginParams;
use bevy_reflect::Reflect;
use indexmap::IndexSet;
use std::marker::PhantomData;

/// Type-parameterized script storage for tracking active scripts
#[derive(Resource, Default, Reflect)]
pub struct KomoToolScriptStore<P, L>
where
    P: IntoScriptPluginParams
        + ScriptFunctionChecker
        + Send
        + Sync
        + 'static
        + std::default::Default,
    L: IntoCallbackLabel + Send + Sync + 'static + std::default::Default,
{
    /// Set of active script identifiers
    #[reflect(ignore)]
    pub scripts: IndexSet<ScriptId>,
    #[reflect(ignore)]
    _phantom: PhantomData<(L, P)>,
}

What went wrong

I get this error:

error[E0277]: cannot add `&std::string::String` to `std::string::String`               
  --> crates\komotool_utils\src\handler\script_store.rs:11:29
   |
11 | #[derive(Resource, Default, Reflect)]
   |                             ^^^^^^^ no implementation for `std::string::String + &std::string::String`
   |
   = help: the trait `std::ops::Add<&std::string::String>` is not implemented for `std::string::String`
   = help: the following other types implement trait `std::ops::Add<Rhs>`:
             `std::string::String` implements `std::ops::Add<&str>`
             `std::string::String` implements `std::ops::Add<smartstring::SmartString<Mode>>`
   = note: this error originates in the derive macro `Reflect` (in Nightly builds, run with -Z macro-backtrace for more info)

Additional information

I tried some things now to this code is also not compiling here is nothing use in BMS:

use super::ScriptFunctionChecker;
use bevy_ecs::system::Resource;
use bevy_mod_scripting::core::event::IntoCallbackLabel;
use bevy_mod_scripting::core::script::ScriptId;
use bevy_mod_scripting::core::IntoScriptPluginParams;
use bevy_reflect::Reflect;
use indexmap::IndexSet;
use std::marker::PhantomData;

/// Type-parameterized script storage for tracking active scripts
#[derive(Resource, Default, Reflect)]
pub struct KomoToolScriptStore<P, L>
/*
where
    P: IntoScriptPluginParams
        + ScriptFunctionChecker
        + Send
        + Sync
        + 'static
        + std::default::Default,
    L: IntoCallbackLabel + Send + Sync + 'static + std::default::Default,

 */
{
    #[reflect(ignore)]
    _phantom: PhantomData<(L, P)>,
}

this compiles:

use super::ScriptFunctionChecker;
use bevy_ecs::system::Resource;
use bevy_mod_scripting::core::event::IntoCallbackLabel;
use bevy_mod_scripting::core::script::ScriptId;
use bevy_mod_scripting::core::IntoScriptPluginParams;
use bevy_reflect::Reflect;
use indexmap::IndexSet;
use std::marker::PhantomData;

/// Type-parameterized script storage for tracking active scripts
#[derive(Resource, Default, Reflect)]
pub struct KomoToolScriptStore<P>
where
    P: IntoScriptPluginParams
        + ScriptFunctionChecker
        + Send
        + Sync
        + 'static
        + std::default::Default,
    //L: IntoCallbackLabel + Send + Sync + 'static + std::default::Default,
{
    /// Set of active script identifiers
    #[reflect(ignore)]
    pub scripts: IndexSet<ScriptId>,
    #[reflect(ignore)]
    _phantom: PhantomData<P>,
}
use super::ScriptFunctionChecker;
use bevy_ecs::system::Resource;
use bevy_mod_scripting::core::event::IntoCallbackLabel;
use bevy_mod_scripting::core::script::ScriptId;
use bevy_mod_scripting::core::IntoScriptPluginParams;
use bevy_reflect::Reflect;
use indexmap::IndexSet;
use std::marker::PhantomData;

/// Type-parameterized script storage for tracking active scripts
#[derive(Resource, Default, Reflect)]
pub struct KomoToolScriptStore<L>
where
    /*
    P: IntoScriptPluginParams
        + ScriptFunctionChecker
        + Send
        + Sync
        + 'static
        + std::default::Default,

     */
    L: IntoCallbackLabel + Send + Sync + 'static + std::default::Default,
{
    /// Set of active script identifiers
    #[reflect(ignore)]
    pub scripts: IndexSet<ScriptId>,
    #[reflect(ignore)]
    _phantom: PhantomData<L>,
}

this also compiles

this is not compiling as well:

use super::ScriptFunctionChecker;
use bevy_ecs::system::Resource;
use bevy_mod_scripting::core::event::IntoCallbackLabel;
use bevy_mod_scripting::core::script::ScriptId;
use bevy_mod_scripting::core::IntoScriptPluginParams;
use bevy_reflect::Reflect;
use indexmap::IndexSet;
use std::marker::PhantomData;

/// Type-parameterized script storage for tracking active scripts
#[derive(Resource, Default, Reflect)]
pub struct KomoToolScriptStore<P, L>
/*
where
    P: IntoScriptPluginParams
        + ScriptFunctionChecker
        + Send
        + Sync
        + 'static
        + std::default::Default
        + Clone,
    L: IntoCallbackLabel + Send + Sync + 'static + std::default::Default + Clone,

 */
{
    #[reflect(ignore)]
    _phantom: PhantomData<(L, P)>,
}

there is a discussion in reflection-dev for more information

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ReflectionRuntime information about typesC-BugAn unexpected or incorrect behaviorD-MacrosCode that generates Rust codeS-Needs-InvestigationThis issue requires detective work to figure out what's going wrong

    Type

    No type

    Projects

    Status

    Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions