diff --git a/crates/bindings-macro/src/table.rs b/crates/bindings-macro/src/table.rs index 1cbba4c5ca1..19fcaec0c9f 100644 --- a/crates/bindings-macro/src/table.rs +++ b/crates/bindings-macro/src/table.rs @@ -1013,10 +1013,21 @@ pub(crate) fn table_impl(mut args: TableArgs, item: &syn::DeriveInput) -> syn::R if let Some(val) = &col.default_value { let ty = &col.ty; let ident_span = col.ident.span(); - Some(quote_spanned! { ident_span => + + // The upper branch of this if clause is special handling for the string type. + if let syn::Type::Path(type_path) = ty + && let Some(segment) = type_path.path.segments.last() + && segment.ident.to_string() == "String" + { + Some(quote_spanned! { ident_span => + let _check: &'static str = #val; + }) + } else { // This closure enforces that `val` is of type `ty` at compile-time. - let _check: #ty = #val; - }) + Some(quote_spanned! { ident_span => + let _check: #ty = #val; + }) + } } else { None } @@ -1026,6 +1037,7 @@ pub(crate) fn table_impl(mut args: TableArgs, item: &syn::DeriveInput) -> syn::R let col_defaults: Vec = columns.iter().filter_map(|col| { if let Some(val) = &col.default_value { let col_id = col.index; + let ty=&col.ty; Some(quote! { spacetimedb::table::ColumnDefault { col_id: #col_id, diff --git a/modules/module-test/src/lib.rs b/modules/module-test/src/lib.rs index fc1851b21b0..0b4aec21478 100644 --- a/modules/module-test/src/lib.rs +++ b/modules/module-test/src/lib.rs @@ -26,6 +26,8 @@ pub struct Person { age: u8, #[default(false)] edited: bool, + #[default("test")] + string: String, } #[cfg(not(feature = "test-add-column"))] @@ -274,6 +276,7 @@ pub fn add(ctx: &ReducerContext, name: String, age: u8) { name, age, edited: false, + string: String::new(), }); #[cfg(not(feature = "test-add-column"))] ctx.db.person().insert(Person { id: 0, name, age });