diff --git a/src/compiler/crystal/interpreter/repl.cr b/src/compiler/crystal/interpreter/repl.cr index 7a09f07484a3..cb0faa82a2c4 100644 --- a/src/compiler/crystal/interpreter/repl.cr +++ b/src/compiler/crystal/interpreter/repl.cr @@ -139,7 +139,7 @@ class Crystal::Repl private def interpret_crystal_exit(exception : EscapingException) decl = UninitializedVar.new(Var.new("ex"), TypeNode.new(@context.program.exception.virtual_type)) - call = Call.new(Path.global("Crystal"), "exit", [NumberLiteral.new(1), Var.new("ex")] of ASTNode) + call = Call.new(Path.global("Crystal"), "exit", NumberLiteral.new(1), Var.new("ex")) exps = Expressions.new([decl, call] of ASTNode) begin diff --git a/src/compiler/crystal/semantic/literal_expander.cr b/src/compiler/crystal/semantic/literal_expander.cr index 0fdc1c36884a..70aa3593225a 100644 --- a/src/compiler/crystal/semantic/literal_expander.cr +++ b/src/compiler/crystal/semantic/literal_expander.cr @@ -53,7 +53,7 @@ module Crystal if node.elements.any?(Splat) ary_var = new_temp_var.at(node) - ary_instance = Call.new(generic, "new", args: [NumberLiteral.new(capacity).at(node)] of ASTNode).at(node) + ary_instance = Call.new(generic, "new", NumberLiteral.new(capacity).at(node)).at(node) exps = Array(ASTNode).new(node.elements.size + 2) exps << Assign.new(ary_var.clone, ary_instance).at(node) @@ -74,7 +74,7 @@ module Crystal else ary_var = new_temp_var.at(node) - ary_instance = Call.new(generic, "unsafe_build", args: [NumberLiteral.new(capacity).at(node)] of ASTNode).at(node) + ary_instance = Call.new(generic, "unsafe_build", NumberLiteral.new(capacity).at(node)).at(node) buffer = Call.new(ary_var, "to_unsafe").at(node) buffer_var = new_temp_var.at(node) @@ -242,7 +242,7 @@ module Crystal exps = Array(ASTNode).new(node.entries.size + 2) exps << Assign.new(temp_var.clone, constructor).at(node) node.entries.each do |entry| - exps << Call.new(temp_var.clone, "[]=", [entry.key.clone, entry.value.clone] of ASTNode).at(node) + exps << Call.new(temp_var.clone, "[]=", entry.key.clone, entry.value.clone).at(node) end exps << temp_var.clone @@ -377,7 +377,7 @@ module Crystal def expand(node : RangeLiteral) path = Path.global("Range").at(node) bool = BoolLiteral.new(node.exclusive?).at(node) - Call.new(path, "new", [node.from, node.to, bool]).at(node) + Call.new(path, "new", node.from, node.to, bool).at(node) end # Convert an interpolation to a call to `String.interpolation` @@ -616,13 +616,14 @@ module Crystal if node_else = node.else case_else = node_else.clone else - case_else = Call.new(nil, "raise", args: [StringLiteral.new("BUG: invalid select index")] of ASTNode, global: true).at(node) + case_else = Call.new(nil, "raise", StringLiteral.new("BUG: invalid select index"), global: true).at(node) end - call_name = node.else ? "non_blocking_select" : "select" - call_args = [TupleLiteral.new(tuple_values).at(node)] of ASTNode - - call = Call.new(channel, call_name, call_args).at(node) + call = Call.new( + channel, + node.else ? "non_blocking_select" : "select", + TupleLiteral.new(tuple_values).at(node), + ).at(node) multi = MultiAssign.new(targets, [call] of ASTNode) case_cond = Var.new(index_name).at(node) a_case = Case.new(case_cond, case_whens, case_else, exhaustive: false).at(node) diff --git a/src/compiler/crystal/semantic/main_visitor.cr b/src/compiler/crystal/semantic/main_visitor.cr index 37a158055543..8758fb48d549 100644 --- a/src/compiler/crystal/semantic/main_visitor.cr +++ b/src/compiler/crystal/semantic/main_visitor.cr @@ -2331,7 +2331,7 @@ module Crystal extra = Call.new( nil, "raise", - args: [StringLiteral.new("Can't instantiate abstract #{base_type.type_desc} #{base_type}")] of ASTNode, + StringLiteral.new("Can't instantiate abstract #{base_type.type_desc} #{base_type}"), global: true) extra.accept self diff --git a/src/compiler/crystal/semantic/method_missing.cr b/src/compiler/crystal/semantic/method_missing.cr index 4511b4a06a06..b48af9b6d4a2 100644 --- a/src/compiler/crystal/semantic/method_missing.cr +++ b/src/compiler/crystal/semantic/method_missing.cr @@ -63,7 +63,7 @@ module Crystal args: args_nodes, named_args: named_args_nodes, block: block_node.is_a?(Block) ? block_node : nil) - fake_call = Call.new(nil, "method_missing", [call] of ASTNode) + fake_call = Call.new(nil, "method_missing", call) expanded_macro, macro_expansion_pragmas = program.expand_macro method_missing, fake_call, self, self diff --git a/src/compiler/crystal/semantic/top_level_visitor.cr b/src/compiler/crystal/semantic/top_level_visitor.cr index 5aa6b26a19b6..313ed25f2a1f 100644 --- a/src/compiler/crystal/semantic/top_level_visitor.cr +++ b/src/compiler/crystal/semantic/top_level_visitor.cr @@ -445,7 +445,7 @@ class Crystal::TopLevelVisitor < Crystal::SemanticVisitor unless @method_added_running @method_added_running = true - run_hooks target_type.metaclass, target_type, :method_added, node, Call.new(nil, "method_added", [node] of ASTNode).at(node.location) + run_hooks target_type.metaclass, target_type, :method_added, node, Call.new(nil, "method_added", node).at(node.location) @method_added_running = false end end diff --git a/src/compiler/crystal/syntax/ast.cr b/src/compiler/crystal/syntax/ast.cr index 2d590ec9e4dd..8b40225a02db 100644 --- a/src/compiler/crystal/syntax/ast.cr +++ b/src/compiler/crystal/syntax/ast.cr @@ -643,14 +643,18 @@ module Crystal end end - def self.new(obj, name, arg : ASTNode) - new obj, name, [arg] of ASTNode + def self.new(obj, name, arg : ASTNode, global = false) + new obj, name, [arg] of ASTNode, global: global end def self.new(obj, name, arg1 : ASTNode, arg2 : ASTNode) new obj, name, [arg1, arg2] of ASTNode end + def self.new(obj, name, arg1 : ASTNode, arg2 : ASTNode, arg3 : ASTNode) + new obj, name, [arg1, arg2, arg3] of ASTNode + end + def self.global(name, arg : ASTNode) new nil, name, [arg] of ASTNode, global: true end diff --git a/src/compiler/crystal/tools/formatter.cr b/src/compiler/crystal/tools/formatter.cr index 74a5577485bf..3c5269a65584 100644 --- a/src/compiler/crystal/tools/formatter.cr +++ b/src/compiler/crystal/tools/formatter.cr @@ -3015,7 +3015,7 @@ module Crystal if body.nil_check? call = Call.new(nil, "nil?") else - call = Call.new(nil, "is_a?", args: [body.const] of ASTNode) + call = Call.new(nil, "is_a?", body.const) end accept call else @@ -3024,7 +3024,7 @@ module Crystal end when RespondsTo if body.obj.is_a?(Var) - call = Call.new(nil, "responds_to?", args: [SymbolLiteral.new(body.name.to_s)] of ASTNode) + call = Call.new(nil, "responds_to?", SymbolLiteral.new(body.name.to_s)) accept call else clear_object(body) @@ -3032,7 +3032,7 @@ module Crystal end when Cast if body.obj.is_a?(Var) - call = Call.new(nil, "as", args: [body.to] of ASTNode) + call = Call.new(nil, "as", body.to) accept call else clear_object(body) @@ -3040,7 +3040,7 @@ module Crystal end when NilableCast if body.obj.is_a?(Var) - call = Call.new(nil, "as?", args: [body.to] of ASTNode) + call = Call.new(nil, "as?", body.to) accept call else clear_object(body)