From d107f63bbb4096529592daeb2ce469030654284b Mon Sep 17 00:00:00 2001 From: Rex Magana Date: Wed, 15 May 2024 21:05:19 -0700 Subject: [PATCH 1/8] Fix CI for latest stable rust (#5) * Remove unused StrRefExt trait * redundant_clone * Unused code --- .../bevy_plugin/tests/test_asset_provider.rs | 20 ------------------- .../add_initial_value_registrations.rs | 4 +++- .../compilation_steps/clean_up_diagnostics.rs | 2 +- .../compiler/src/compiler/antlr_rust_ext.rs | 15 -------------- .../src/listeners/compiler_listener.rs | 8 +++++--- .../string_table_generator_visitor.rs | 8 ++++++-- .../src/visitors/type_check_visitor.rs | 2 +- crates/core/src/types/type.rs | 12 ----------- crates/runtime/src/virtual_machine.rs | 2 +- .../yarnspinner/tests/test_base/test_plan.rs | 2 +- 10 files changed, 18 insertions(+), 57 deletions(-) diff --git a/crates/bevy_plugin/tests/test_asset_provider.rs b/crates/bevy_plugin/tests/test_asset_provider.rs index 023baf68..3bd4f6b7 100644 --- a/crates/bevy_plugin/tests/test_asset_provider.rs +++ b/crates/bevy_plugin/tests/test_asset_provider.rs @@ -3,7 +3,6 @@ use anyhow::{bail, Result}; use bevy::prelude::*; use bevy::utils::Instant; use bevy_yarnspinner::prelude::*; -use bevy_yarnspinner::UnderlyingYarnLine; use utils::prelude::*; mod utils; @@ -198,22 +197,3 @@ fn does_not_load_asset_with_invalid_type() -> Result<()> { assert!(asset.is_none()); Ok(()) } - -trait AssetProviderExt { - fn get_assets_for_id(&self, id: &str) -> LineAssets; -} - -impl AssetProviderExt for T -where - T: AssetProvider + ?Sized, -{ - fn get_assets_for_id(&self, id: &str) -> LineAssets { - let line_id = LineId(id.to_owned()); - let yarn_line = UnderlyingYarnLine { - id: line_id, - text: String::new(), - attributes: vec![], - }; - T::get_assets(self, &yarn_line) - } -} diff --git a/crates/compiler/src/compilation_steps/add_initial_value_registrations.rs b/crates/compiler/src/compilation_steps/add_initial_value_registrations.rs index 05e79ed0..5a1a16dd 100644 --- a/crates/compiler/src/compilation_steps/add_initial_value_registrations.rs +++ b/crates/compiler/src/compilation_steps/add_initial_value_registrations.rs @@ -39,6 +39,8 @@ pub(crate) fn add_initial_value_registrations( } } - compilation.declarations = state.derived_variable_declarations.clone(); + compilation + .declarations + .clone_from(&state.derived_variable_declarations); state } diff --git a/crates/compiler/src/compilation_steps/clean_up_diagnostics.rs b/crates/compiler/src/compilation_steps/clean_up_diagnostics.rs index fa087252..f3203c99 100644 --- a/crates/compiler/src/compilation_steps/clean_up_diagnostics.rs +++ b/crates/compiler/src/compilation_steps/clean_up_diagnostics.rs @@ -27,7 +27,7 @@ pub(crate) fn clean_up_diagnostics(mut state: CompilationIntermediate) -> Compil if state.diagnostics.has_errors() { state.result = Some(Err(CompilerError(state.diagnostics.clone()))); } else if let Some(Ok(compilation)) = state.result.as_mut() { - compilation.warnings = state.diagnostics.clone(); + compilation.warnings.clone_from(&state.diagnostics); } state } diff --git a/crates/compiler/src/compiler/antlr_rust_ext.rs b/crates/compiler/src/compiler/antlr_rust_ext.rs index 08beae0a..d50abc73 100644 --- a/crates/compiler/src/compiler/antlr_rust_ext.rs +++ b/crates/compiler/src/compiler/antlr_rust_ext.rs @@ -1,15 +1,11 @@ //! Contains functionality provided in the C# implementation of ANTLR but not (yet?) in antlr4rust. -use crate::parser::generated::yarnspinnerparser::YarnSpinnerParserContextType; use crate::parser::ActualTokenStream; use crate::prelude::generated::yarnspinnerparser::YarnSpinnerParserContext; -use crate::prelude::ContextRefExt; use antlr_rust::int_stream::IntStream; -use antlr_rust::rule_context::RuleContext; use antlr_rust::token::{CommonToken, Token, TOKEN_DEFAULT_CHANNEL}; use antlr_rust::token_factory::{CommonTokenFactory, TokenFactory}; use antlr_rust::token_stream::TokenStream; -use antlr_rust::tree::ErrorNode; use antlr_rust::InputStream; use better_any::TidExt; use std::rc::Rc; @@ -209,17 +205,6 @@ pub(crate) trait YarnSpinnerParserContextExt<'input>: .filter_map(|child| child.downcast_rc::().ok()) .nth(pos) } - - /// Adapted from - fn add_error_node( - &self, - bad_token: CommonToken<'input>, - ) -> Rc> { - let error_node = Rc::new(ErrorNode::new(Box::new(bad_token))); - error_node.set_parent(&Some(self.ref_to_rc())); - self.add_child(error_node.clone()); - error_node - } } impl<'input, T: YarnSpinnerParserContext<'input> + ?Sized> YarnSpinnerParserContextExt<'input> for T diff --git a/crates/compiler/src/listeners/compiler_listener.rs b/crates/compiler/src/listeners/compiler_listener.rs index 87d94efc..e0006aca 100644 --- a/crates/compiler/src/listeners/compiler_listener.rs +++ b/crates/compiler/src/listeners/compiler_listener.rs @@ -99,8 +99,10 @@ impl<'input> YarnSpinnerParserListener<'input> for CompilerListener<'input> { // Duplicate node name! We'll have caught this during the // declarations pass, so no need to issue an error here. } - self.current_debug_info.node_name = name.clone(); - self.current_debug_info.file_name = self.file.name.clone(); + self.current_debug_info.node_name.clone_from(name); + self.current_debug_info + .file_name + .clone_from(&self.file.name); self.debug_infos .borrow_mut() .push(self.current_debug_info.clone()); @@ -130,7 +132,7 @@ impl<'input> YarnSpinnerParserListener<'input> for CompilerListener<'input> { match header_key { "title" => { // Set the name of the node - current_node.name = header_value.clone(); + current_node.name.clone_from(&header_value); } "tags" => { // Split the list of tags by spaces, and use that diff --git a/crates/compiler/src/visitors/string_table_generator_visitor.rs b/crates/compiler/src/visitors/string_table_generator_visitor.rs index 36db2bd1..3d2e55e3 100644 --- a/crates/compiler/src/visitors/string_table_generator_visitor.rs +++ b/crates/compiler/src/visitors/string_table_generator_visitor.rs @@ -51,8 +51,12 @@ impl<'input> YarnSpinnerParserVisitorCompat<'input> for StringTableGeneratorVisi for header in ctx.header_all() { let header_key = header.header_key.as_ref().unwrap().get_text(); if header_key == "title" { - self.current_node_name = - header.header_value.as_ref().unwrap().get_text().to_owned(); + header + .header_value + .as_ref() + .unwrap() + .get_text() + .clone_into(&mut self.current_node_name) } else if header_key == "tags" { let header_value = header .header_value diff --git a/crates/compiler/src/visitors/type_check_visitor.rs b/crates/compiler/src/visitors/type_check_visitor.rs index ee1c97c1..341889d5 100644 --- a/crates/compiler/src/visitors/type_check_visitor.rs +++ b/crates/compiler/src/visitors/type_check_visitor.rs @@ -361,7 +361,7 @@ impl<'input> YarnSpinnerParserVisitorCompat<'input> for TypeCheckVisitor<'input> let Type::Function(function_type) = &mut declaration.r#type else { unreachable!(); }; - function_type.parameters[i] = supplied_type.clone(); + function_type.parameters[i].clone_from(&supplied_type); expected_type = &supplied_type; } if !supplied_type.is_sub_type_of(expected_type) { diff --git a/crates/core/src/types/type.rs b/crates/core/src/types/type.rs index 05a7e19d..f036441a 100644 --- a/crates/core/src/types/type.rs +++ b/crates/core/src/types/type.rs @@ -209,18 +209,6 @@ impl_type! { Type::Boolean => [bool,], } -// The macro has problems with the following expansions - -trait StrRefExt { - fn r#type() -> Type; -} - -impl StrRefExt for &str { - fn r#type() -> Type { - Type::String - } -} - impl From<&str> for Type { fn from(_value: &str) -> Self { Type::String diff --git a/crates/runtime/src/virtual_machine.rs b/crates/runtime/src/virtual_machine.rs index 1d823c32..e847addb 100644 --- a/crates/runtime/src/virtual_machine.rs +++ b/crates/runtime/src/virtual_machine.rs @@ -82,7 +82,7 @@ impl VirtualMachine { pub(crate) fn set_language_code(&mut self, language_code: impl Into>) { let language_code = language_code.into(); - self.language_code = language_code.clone(); + self.language_code.clone_from(&language_code); self.line_parser.set_language_code(language_code.clone()); self.text_provider.set_language(language_code); } diff --git a/crates/yarnspinner/tests/test_base/test_plan.rs b/crates/yarnspinner/tests/test_base/test_plan.rs index 3ec3f4b2..15cce09a 100644 --- a/crates/yarnspinner/tests/test_base/test_plan.rs +++ b/crates/yarnspinner/tests/test_base/test_plan.rs @@ -66,7 +66,7 @@ impl TestPlan { }); } else { self.next_expected_step = current_step.expected_step_type; - self.next_step_value = current_step.value.clone(); + self.next_step_value.clone_from(¤t_step.value); return; } } From 94d183b9c9587601baa1e7276ceb650d9384624b Mon Sep 17 00:00:00 2001 From: Rex Magana Date: Mon, 4 Mar 2024 16:52:29 -0800 Subject: [PATCH 2/8] extend variable storage function --- crates/runtime/src/dialogue.rs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/crates/runtime/src/dialogue.rs b/crates/runtime/src/dialogue.rs index 4e9d94bd..63e177dc 100644 --- a/crates/runtime/src/dialogue.rs +++ b/crates/runtime/src/dialogue.rs @@ -219,10 +219,27 @@ impl Dialogue { self.vm.continue_() } + fn extend_variable_storage_from(&mut self, program: &Program) { + let initial: HashMap = program + .initial_values + .iter() + .map(|(k, v)| (k.clone(), v.clone().into())) + .collect(); + + // Extend the VariableStorage with the initial values from the program + if let Err(e) = self.variable_storage_mut().extend(initial) { + error!( + "Failed to populate VariableStorage with initial values: {}", + e + ); + } + } + /// Sets or replaces the [`Dialogue`]'s current [`Program`]. The program is replaced, all current state is reset. pub fn replace_program(&mut self, program: Program) -> &mut Self { - self.vm.program.replace(program); + self.vm.program.replace(program.clone()); self.vm.reset_state(); + self.extend_variable_storage_from(&program); self } @@ -231,8 +248,9 @@ impl Dialogue { if let Some(existing_program) = self.vm.program.as_mut() { *existing_program = Program::combine(vec![existing_program.clone(), program]).unwrap(); } else { - self.vm.program.replace(program); + self.vm.program.replace(program.clone()); self.vm.reset_state(); + self.extend_variable_storage_from(&program); } self From 7caa9ce8d6a0dd1fae00230cd7c690971e553144 Mon Sep 17 00:00:00 2001 From: Rex Magana Date: Mon, 4 Mar 2024 17:15:33 -0800 Subject: [PATCH 3/8] Extend either way --- crates/runtime/src/dialogue.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/runtime/src/dialogue.rs b/crates/runtime/src/dialogue.rs index 63e177dc..33516468 100644 --- a/crates/runtime/src/dialogue.rs +++ b/crates/runtime/src/dialogue.rs @@ -246,12 +246,13 @@ impl Dialogue { /// Merges the currently set [`Program`] with the given one. If there is no program set, the given one is set. pub fn add_program(&mut self, program: Program) -> &mut Self { if let Some(existing_program) = self.vm.program.as_mut() { - *existing_program = Program::combine(vec![existing_program.clone(), program]).unwrap(); + *existing_program = + Program::combine(vec![existing_program.clone(), program.clone()]).unwrap(); } else { self.vm.program.replace(program.clone()); self.vm.reset_state(); - self.extend_variable_storage_from(&program); } + self.extend_variable_storage_from(&program); self } From af0991d19e7f48ef39501ee513da1716f4571549 Mon Sep 17 00:00:00 2001 From: Rex Magana Date: Thu, 16 May 2024 17:33:29 -0700 Subject: [PATCH 4/8] Fix tests to use right data type --- crates/yarnspinner/tests/type_tests.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/crates/yarnspinner/tests/type_tests.rs b/crates/yarnspinner/tests/type_tests.rs index 4e1d20c3..09eabe4b 100644 --- a/crates/yarnspinner/tests/type_tests.rs +++ b/crates/yarnspinner/tests/type_tests.rs @@ -402,25 +402,25 @@ fn test_initial_values() -> anyhow::Result<()> { // so this would be "True" instead. .expect_line("true") // external decls - .expect_line("42") - .expect_line("Hello") + .expect_line("0") + .expect_line("Bye") // ## Implementation note: See above - .expect_line("true"), + .expect_line("false"), ); let result = Compiler::from_test_source(source) .extend_library(test_base.dialogue.library().clone()) + .declare_variable(Declaration::new("$external_str", Type::String).with_default_value("Bye")) + .declare_variable(Declaration::new("$external_int", Type::Number).with_default_value(0)) .declare_variable( - Declaration::new("$external_str", Type::String).with_default_value("Hello"), + Declaration::new("$external_bool", Type::Boolean).with_default_value(false), ) - .declare_variable(Declaration::new("$external_int", Type::Boolean).with_default_value(true)) - .declare_variable(Declaration::new("$external_bool", Type::Number).with_default_value(42)) .compile()?; let mut variable_storage = test_base.variable_storage.clone_shallow(); - variable_storage.set("$external_str".to_string(), "Hello".into())?; - variable_storage.set("$external_int".to_string(), 42.into())?; - variable_storage.set("$external_bool".to_string(), true.into())?; + variable_storage.set("$external_str".to_string(), "Bye".into())?; + variable_storage.set("$external_int".to_string(), 0.into())?; + variable_storage.set("$external_bool".to_string(), false.into())?; test_base.with_compilation(result).run_standard_testcase(); Ok(()) From 9950c19208be40fd6dc554577ebc4ab6145b5e9a Mon Sep 17 00:00:00 2001 From: Rex Magana Date: Thu, 16 May 2024 17:47:46 -0700 Subject: [PATCH 5/8] Add test --- crates/yarnspinner/tests/type_tests.rs | 31 ++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/crates/yarnspinner/tests/type_tests.rs b/crates/yarnspinner/tests/type_tests.rs index 09eabe4b..426fe484 100644 --- a/crates/yarnspinner/tests/type_tests.rs +++ b/crates/yarnspinner/tests/type_tests.rs @@ -426,6 +426,37 @@ fn test_initial_values() -> anyhow::Result<()> { Ok(()) } +#[test] +fn test_variable_storage_extended_with_program_initial_values() { + let source = " + <> + <> + <> + "; + + let result = Compiler::from_test_source(source).compile().unwrap(); + + let mut dialogue = Dialogue::new( + Box::new(MemoryVariableStorage::new()), + Box::new(StringTableTextProvider::new()), + ); + dialogue.replace_program(result.program.unwrap()); + + let variable_storage = dialogue.variable_storage(); + assert_eq!( + variable_storage.get("$int").unwrap(), + YarnValue::Number(42.0) + ); + assert_eq!( + variable_storage.get("$str").unwrap(), + YarnValue::String("Hello".to_string()) + ); + assert_eq!( + variable_storage.get("$bool").unwrap(), + YarnValue::Boolean(true) + ); +} + #[test] fn test_explicit_types() { let result = Compiler::from_test_source( From 0a2eb9d69ac8e3fe1df6a3f4b017c4deddd13043 Mon Sep 17 00:00:00 2001 From: Rex Magana Date: Thu, 16 May 2024 17:51:02 -0700 Subject: [PATCH 6/8] Revert "Fix CI for latest stable rust (#5)" This reverts commit d107f63bbb4096529592daeb2ce469030654284b. --- .../bevy_plugin/tests/test_asset_provider.rs | 20 +++++++++++++++++++ .../add_initial_value_registrations.rs | 4 +--- .../compilation_steps/clean_up_diagnostics.rs | 2 +- .../compiler/src/compiler/antlr_rust_ext.rs | 15 ++++++++++++++ .../src/listeners/compiler_listener.rs | 8 +++----- .../string_table_generator_visitor.rs | 8 ++------ .../src/visitors/type_check_visitor.rs | 2 +- crates/core/src/types/type.rs | 12 +++++++++++ crates/runtime/src/virtual_machine.rs | 2 +- .../yarnspinner/tests/test_base/test_plan.rs | 2 +- 10 files changed, 57 insertions(+), 18 deletions(-) diff --git a/crates/bevy_plugin/tests/test_asset_provider.rs b/crates/bevy_plugin/tests/test_asset_provider.rs index 3bd4f6b7..023baf68 100644 --- a/crates/bevy_plugin/tests/test_asset_provider.rs +++ b/crates/bevy_plugin/tests/test_asset_provider.rs @@ -3,6 +3,7 @@ use anyhow::{bail, Result}; use bevy::prelude::*; use bevy::utils::Instant; use bevy_yarnspinner::prelude::*; +use bevy_yarnspinner::UnderlyingYarnLine; use utils::prelude::*; mod utils; @@ -197,3 +198,22 @@ fn does_not_load_asset_with_invalid_type() -> Result<()> { assert!(asset.is_none()); Ok(()) } + +trait AssetProviderExt { + fn get_assets_for_id(&self, id: &str) -> LineAssets; +} + +impl AssetProviderExt for T +where + T: AssetProvider + ?Sized, +{ + fn get_assets_for_id(&self, id: &str) -> LineAssets { + let line_id = LineId(id.to_owned()); + let yarn_line = UnderlyingYarnLine { + id: line_id, + text: String::new(), + attributes: vec![], + }; + T::get_assets(self, &yarn_line) + } +} diff --git a/crates/compiler/src/compilation_steps/add_initial_value_registrations.rs b/crates/compiler/src/compilation_steps/add_initial_value_registrations.rs index 5a1a16dd..05e79ed0 100644 --- a/crates/compiler/src/compilation_steps/add_initial_value_registrations.rs +++ b/crates/compiler/src/compilation_steps/add_initial_value_registrations.rs @@ -39,8 +39,6 @@ pub(crate) fn add_initial_value_registrations( } } - compilation - .declarations - .clone_from(&state.derived_variable_declarations); + compilation.declarations = state.derived_variable_declarations.clone(); state } diff --git a/crates/compiler/src/compilation_steps/clean_up_diagnostics.rs b/crates/compiler/src/compilation_steps/clean_up_diagnostics.rs index f3203c99..fa087252 100644 --- a/crates/compiler/src/compilation_steps/clean_up_diagnostics.rs +++ b/crates/compiler/src/compilation_steps/clean_up_diagnostics.rs @@ -27,7 +27,7 @@ pub(crate) fn clean_up_diagnostics(mut state: CompilationIntermediate) -> Compil if state.diagnostics.has_errors() { state.result = Some(Err(CompilerError(state.diagnostics.clone()))); } else if let Some(Ok(compilation)) = state.result.as_mut() { - compilation.warnings.clone_from(&state.diagnostics); + compilation.warnings = state.diagnostics.clone(); } state } diff --git a/crates/compiler/src/compiler/antlr_rust_ext.rs b/crates/compiler/src/compiler/antlr_rust_ext.rs index d50abc73..08beae0a 100644 --- a/crates/compiler/src/compiler/antlr_rust_ext.rs +++ b/crates/compiler/src/compiler/antlr_rust_ext.rs @@ -1,11 +1,15 @@ //! Contains functionality provided in the C# implementation of ANTLR but not (yet?) in antlr4rust. +use crate::parser::generated::yarnspinnerparser::YarnSpinnerParserContextType; use crate::parser::ActualTokenStream; use crate::prelude::generated::yarnspinnerparser::YarnSpinnerParserContext; +use crate::prelude::ContextRefExt; use antlr_rust::int_stream::IntStream; +use antlr_rust::rule_context::RuleContext; use antlr_rust::token::{CommonToken, Token, TOKEN_DEFAULT_CHANNEL}; use antlr_rust::token_factory::{CommonTokenFactory, TokenFactory}; use antlr_rust::token_stream::TokenStream; +use antlr_rust::tree::ErrorNode; use antlr_rust::InputStream; use better_any::TidExt; use std::rc::Rc; @@ -205,6 +209,17 @@ pub(crate) trait YarnSpinnerParserContextExt<'input>: .filter_map(|child| child.downcast_rc::().ok()) .nth(pos) } + + /// Adapted from + fn add_error_node( + &self, + bad_token: CommonToken<'input>, + ) -> Rc> { + let error_node = Rc::new(ErrorNode::new(Box::new(bad_token))); + error_node.set_parent(&Some(self.ref_to_rc())); + self.add_child(error_node.clone()); + error_node + } } impl<'input, T: YarnSpinnerParserContext<'input> + ?Sized> YarnSpinnerParserContextExt<'input> for T diff --git a/crates/compiler/src/listeners/compiler_listener.rs b/crates/compiler/src/listeners/compiler_listener.rs index e0006aca..87d94efc 100644 --- a/crates/compiler/src/listeners/compiler_listener.rs +++ b/crates/compiler/src/listeners/compiler_listener.rs @@ -99,10 +99,8 @@ impl<'input> YarnSpinnerParserListener<'input> for CompilerListener<'input> { // Duplicate node name! We'll have caught this during the // declarations pass, so no need to issue an error here. } - self.current_debug_info.node_name.clone_from(name); - self.current_debug_info - .file_name - .clone_from(&self.file.name); + self.current_debug_info.node_name = name.clone(); + self.current_debug_info.file_name = self.file.name.clone(); self.debug_infos .borrow_mut() .push(self.current_debug_info.clone()); @@ -132,7 +130,7 @@ impl<'input> YarnSpinnerParserListener<'input> for CompilerListener<'input> { match header_key { "title" => { // Set the name of the node - current_node.name.clone_from(&header_value); + current_node.name = header_value.clone(); } "tags" => { // Split the list of tags by spaces, and use that diff --git a/crates/compiler/src/visitors/string_table_generator_visitor.rs b/crates/compiler/src/visitors/string_table_generator_visitor.rs index 3d2e55e3..36db2bd1 100644 --- a/crates/compiler/src/visitors/string_table_generator_visitor.rs +++ b/crates/compiler/src/visitors/string_table_generator_visitor.rs @@ -51,12 +51,8 @@ impl<'input> YarnSpinnerParserVisitorCompat<'input> for StringTableGeneratorVisi for header in ctx.header_all() { let header_key = header.header_key.as_ref().unwrap().get_text(); if header_key == "title" { - header - .header_value - .as_ref() - .unwrap() - .get_text() - .clone_into(&mut self.current_node_name) + self.current_node_name = + header.header_value.as_ref().unwrap().get_text().to_owned(); } else if header_key == "tags" { let header_value = header .header_value diff --git a/crates/compiler/src/visitors/type_check_visitor.rs b/crates/compiler/src/visitors/type_check_visitor.rs index 341889d5..ee1c97c1 100644 --- a/crates/compiler/src/visitors/type_check_visitor.rs +++ b/crates/compiler/src/visitors/type_check_visitor.rs @@ -361,7 +361,7 @@ impl<'input> YarnSpinnerParserVisitorCompat<'input> for TypeCheckVisitor<'input> let Type::Function(function_type) = &mut declaration.r#type else { unreachable!(); }; - function_type.parameters[i].clone_from(&supplied_type); + function_type.parameters[i] = supplied_type.clone(); expected_type = &supplied_type; } if !supplied_type.is_sub_type_of(expected_type) { diff --git a/crates/core/src/types/type.rs b/crates/core/src/types/type.rs index f036441a..05a7e19d 100644 --- a/crates/core/src/types/type.rs +++ b/crates/core/src/types/type.rs @@ -209,6 +209,18 @@ impl_type! { Type::Boolean => [bool,], } +// The macro has problems with the following expansions + +trait StrRefExt { + fn r#type() -> Type; +} + +impl StrRefExt for &str { + fn r#type() -> Type { + Type::String + } +} + impl From<&str> for Type { fn from(_value: &str) -> Self { Type::String diff --git a/crates/runtime/src/virtual_machine.rs b/crates/runtime/src/virtual_machine.rs index e847addb..1d823c32 100644 --- a/crates/runtime/src/virtual_machine.rs +++ b/crates/runtime/src/virtual_machine.rs @@ -82,7 +82,7 @@ impl VirtualMachine { pub(crate) fn set_language_code(&mut self, language_code: impl Into>) { let language_code = language_code.into(); - self.language_code.clone_from(&language_code); + self.language_code = language_code.clone(); self.line_parser.set_language_code(language_code.clone()); self.text_provider.set_language(language_code); } diff --git a/crates/yarnspinner/tests/test_base/test_plan.rs b/crates/yarnspinner/tests/test_base/test_plan.rs index 15cce09a..3ec3f4b2 100644 --- a/crates/yarnspinner/tests/test_base/test_plan.rs +++ b/crates/yarnspinner/tests/test_base/test_plan.rs @@ -66,7 +66,7 @@ impl TestPlan { }); } else { self.next_expected_step = current_step.expected_step_type; - self.next_step_value.clone_from(¤t_step.value); + self.next_step_value = current_step.value.clone(); return; } } From 22f524f8b7d679cb7d133592876f2c71760396f0 Mon Sep 17 00:00:00 2001 From: Rex Magana Date: Fri, 17 May 2024 07:29:45 -0700 Subject: [PATCH 7/8] Trigger CI From 09457ed6d37bfa72dc54237481631a667365c57b Mon Sep 17 00:00:00 2001 From: Rex Magana Date: Fri, 17 May 2024 09:53:06 -0700 Subject: [PATCH 8/8] Revert changed variables --- crates/yarnspinner/tests/type_tests.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/crates/yarnspinner/tests/type_tests.rs b/crates/yarnspinner/tests/type_tests.rs index 426fe484..e903c822 100644 --- a/crates/yarnspinner/tests/type_tests.rs +++ b/crates/yarnspinner/tests/type_tests.rs @@ -402,25 +402,27 @@ fn test_initial_values() -> anyhow::Result<()> { // so this would be "True" instead. .expect_line("true") // external decls - .expect_line("0") - .expect_line("Bye") + .expect_line("42") + .expect_line("Hello") // ## Implementation note: See above - .expect_line("false"), + .expect_line("true"), ); let result = Compiler::from_test_source(source) .extend_library(test_base.dialogue.library().clone()) - .declare_variable(Declaration::new("$external_str", Type::String).with_default_value("Bye")) - .declare_variable(Declaration::new("$external_int", Type::Number).with_default_value(0)) .declare_variable( - Declaration::new("$external_bool", Type::Boolean).with_default_value(false), + Declaration::new("$external_str", Type::String).with_default_value("Hello"), + ) + .declare_variable(Declaration::new("$external_int", Type::Number).with_default_value(42)) + .declare_variable( + Declaration::new("$external_bool", Type::Boolean).with_default_value(true), ) .compile()?; let mut variable_storage = test_base.variable_storage.clone_shallow(); - variable_storage.set("$external_str".to_string(), "Bye".into())?; - variable_storage.set("$external_int".to_string(), 0.into())?; - variable_storage.set("$external_bool".to_string(), false.into())?; + variable_storage.set("$external_str".to_string(), "Hello".into())?; + variable_storage.set("$external_int".to_string(), 42.into())?; + variable_storage.set("$external_bool".to_string(), true.into())?; test_base.with_compilation(result).run_standard_testcase(); Ok(())