Skip to content

Commit

Permalink
Update Ast::EnumDestructuring#parameters to Nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewmcgarvey committed May 22, 2021
1 parent 0d910dc commit 5639279
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/ast/enum_destructuring.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 5 additions & 2 deletions src/compilers/case_branch.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
2 changes: 1 addition & 1 deletion src/parsers/enum_destructuring.cr
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module Mint

option = type_id! EnumDestructuringExpectedOption

parameters = [] of Ast::TypeVariable
parameters = [] of Ast::Node

if char! '('
parameters.concat list(
Expand Down
34 changes: 20 additions & 14 deletions src/type_checkers/case_branch.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 5639279

Please sign in to comment.