From 5639279e7f45c9328bd10f07817a4fe1c10272fa Mon Sep 17 00:00:00 2001 From: matthewmcgarvey Date: Thu, 20 May 2021 22:18:25 -0400 Subject: [PATCH] Update Ast::EnumDestructuring#parameters to Nodes --- src/ast/enum_destructuring.cr | 2 +- src/compilers/case_branch.cr | 7 +++++-- src/parsers/enum_destructuring.cr | 2 +- src/type_checkers/case_branch.cr | 34 ++++++++++++++++++------------- 4 files changed, 27 insertions(+), 18 deletions(-) diff --git a/src/ast/enum_destructuring.cr b/src/ast/enum_destructuring.cr index 19942e99a..511f1b250 100644 --- a/src/ast/enum_destructuring.cr +++ b/src/ast/enum_destructuring.cr @@ -3,7 +3,7 @@ module Mint class EnumDestructuring < Node getter name, option, parameters - def initialize(@parameters : Array(TypeVariable), + def initialize(@parameters : Array(Node), @option : String, @name : String, @input : Data, diff --git a/src/compilers/case_branch.cr b/src/compilers/case_branch.cr index 15c6c36d3..0d1e13661 100644 --- a/src/compilers/case_branch.cr +++ b/src/compilers/case_branch.cr @@ -55,8 +55,11 @@ module Mint variables = case lookups[match].as(Ast::EnumOption).parameters[0]? when Ast::EnumRecordDefinition - match.parameters.map do |param| - "const #{js.variable_of(param)} = #{variable}._0.#{param.value}" + match.parameters.compact_map do |param| + case param + when Ast::TypeVariable + "const #{js.variable_of(param)} = #{variable}._0.#{param.value}" + end end else match.parameters.map_with_index do |param, index1| diff --git a/src/parsers/enum_destructuring.cr b/src/parsers/enum_destructuring.cr index d841af868..cbc06cb07 100644 --- a/src/parsers/enum_destructuring.cr +++ b/src/parsers/enum_destructuring.cr @@ -12,7 +12,7 @@ module Mint option = type_id! EnumDestructuringExpectedOption - parameters = [] of Ast::TypeVariable + parameters = [] of Ast::Node if char! '(' parameters.concat list( diff --git a/src/type_checkers/case_branch.cr b/src/type_checkers/case_branch.cr index 7a33570fa..39fbe14d1 100644 --- a/src/type_checkers/case_branch.cr +++ b/src/type_checkers/case_branch.cr @@ -84,28 +84,34 @@ module Mint case option_param = option.parameters[0]? when Ast::EnumRecordDefinition - item.parameters.map do |param| - record = - resolve(option_param).as(Record) + item.parameters.compact_map do |param| + case param + when Ast::TypeVariable + record = + resolve(option_param).as(Record) - {param.value, record.fields[param.value], param} + {param.value, record.fields[param.value], param} + end end else item.parameters.map_with_index do |param, index| - option_type = - resolve(option.parameters[index]).not_nil! + case param + when Ast::TypeVariable + option_type = + resolve(option.parameters[index]).not_nil! - mapping = {} of String => Checkable + mapping = {} of String => Checkable - entity.parameters.each_with_index do |param2, index2| - mapping[param2.value] = condition.parameters[index2] - end + entity.parameters.each_with_index do |param2, index2| + mapping[param2.value] = condition.parameters[index2] + end - resolved_type = - Comparer.fill(option_type, mapping) + resolved_type = + Comparer.fill(option_type, mapping) - {param.value, resolved_type.not_nil!, param} - end + {param.value, resolved_type.not_nil!, param} + end + end.compact end end