diff --git a/src/compiler/crystal/semantic/bindings.cr b/src/compiler/crystal/semantic/bindings.cr index 2fa50391d564..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,13 +132,9 @@ module Crystal dependencies = @dependencies ||= [] of ASTNode - node = yield dependencies + 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 +149,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 +204,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)