From 41ba23d7abe8361d2d7435b931e85991bfc93c18 Mon Sep 17 00:00:00 2001 From: Filip Tibell Date: Wed, 22 Feb 2023 12:40:48 +0100 Subject: [PATCH] Fix unification of arg types in unions where one side has nil(s) --- packages/cli/src/gen/definitions/parser.rs | 1 + packages/cli/src/gen/definitions/type_info_ext.rs | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/cli/src/gen/definitions/parser.rs b/packages/cli/src/gen/definitions/parser.rs index 5739c4e..1c09882 100644 --- a/packages/cli/src/gen/definitions/parser.rs +++ b/packages/cli/src/gen/definitions/parser.rs @@ -142,6 +142,7 @@ impl DefinitionsParser { results.push(self.convert_parser_item_into_doc_item(top_level_item.clone())); } self.found_top_level_items = BTreeMap::new(); + self.found_top_level_types = HashMap::new(); self.found_top_level_declares = Vec::new(); Ok(results) } diff --git a/packages/cli/src/gen/definitions/type_info_ext.rs b/packages/cli/src/gen/definitions/type_info_ext.rs index 0354a6d..f2ddaa3 100644 --- a/packages/cli/src/gen/definitions/type_info_ext.rs +++ b/packages/cli/src/gen/definitions/type_info_ext.rs @@ -247,6 +247,16 @@ impl TypeInfoExt for TypeInfo { } } +fn make_empty_type_argument() -> TypeArgument { + TypeArgument::new(TypeInfo::Basic(TokenReference::new( + vec![], + Token::new(TokenType::Symbol { + symbol: Symbol::Nil, + }), + vec![], + ))) +} + fn merge_type_arguments(left: TypeArgument, right: TypeArgument) -> TypeArgument { TypeArgument::new(TypeInfo::Union { left: Box::new(left.type_info().clone()), @@ -270,7 +280,10 @@ fn merge_type_argument_vecs( if let Some(existing) = existing.get(index) { result.push(merge_type_arguments(existing.clone(), argument.clone())); } else { - result.push(argument.clone()); + result.push(merge_type_arguments( + make_empty_type_argument(), + argument.clone(), + )); } } result