From 37a525fd686823fbb4948f985eeb6fc6e109fe6a Mon Sep 17 00:00:00 2001 From: Ary Borenszweig Date: Thu, 1 Sep 2022 09:41:40 -0300 Subject: [PATCH 1/2] Extract type_from_dependencies --- src/compiler/crystal/semantic/bindings.cr | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/compiler/crystal/semantic/bindings.cr b/src/compiler/crystal/semantic/bindings.cr index 2fa50391d564..b5a7a0cc656e 100644 --- a/src/compiler/crystal/semantic/bindings.cr +++ b/src/compiler/crystal/semantic/bindings.cr @@ -136,11 +136,7 @@ module Crystal node = yield dependencies - if dependencies.size == 1 - new_type = node.type? - else - new_type = Type.merge dependencies - end + new_type = type_from_dependencies new_type = map_type(new_type) if new_type if new_type && (freeze_type = self.freeze_type) @@ -155,6 +151,10 @@ module Crystal propagate end + def type_from_dependencies : Type? + Type.merge dependencies + end + def unbind_from(nodes : Nil) # Nothing to do end @@ -206,7 +206,7 @@ module Crystal def update(from = nil) return if @type && @type.same? from.try &.type? - new_type = Type.merge dependencies + new_type = type_from_dependencies new_type = map_type(new_type) if new_type if new_type && (freeze_type = self.freeze_type) From b85f7203f75a155e069adf8b33257f8b107ec439 Mon Sep 17 00:00:00 2001 From: Ary Borenszweig Date: Thu, 1 Sep 2022 09:42:39 -0300 Subject: [PATCH 2/2] No need for bind's yield to return anything --- src/compiler/crystal/semantic/bindings.cr | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/compiler/crystal/semantic/bindings.cr b/src/compiler/crystal/semantic/bindings.cr index b5a7a0cc656e..c866998dbb12 100644 --- a/src/compiler/crystal/semantic/bindings.cr +++ b/src/compiler/crystal/semantic/bindings.cr @@ -106,21 +106,19 @@ module Crystal @type end - def bind_to(node : ASTNode) + def bind_to(node : ASTNode) : Nil bind(node) do |dependencies| dependencies.push node node.add_observer self - node end end - def bind_to(nodes : Indexable) + def bind_to(nodes : Indexable) : Nil return if nodes.empty? bind do |dependencies| dependencies.concat nodes nodes.each &.add_observer self - nodes.first end end @@ -134,7 +132,7 @@ module Crystal dependencies = @dependencies ||= [] of ASTNode - node = yield dependencies + yield dependencies new_type = type_from_dependencies new_type = map_type(new_type) if new_type