From cf8b4b9083299305d6842f59b112fe48d9c5da6f Mon Sep 17 00:00:00 2001 From: Ary Borenszweig Date: Sat, 18 Aug 2018 11:04:31 -0300 Subject: [PATCH] Fix: check presence of named argument via external name --- spec/compiler/normalize/def_spec.cr | 6 ++++++ src/compiler/crystal/semantic/default_arguments.cr | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/spec/compiler/normalize/def_spec.cr b/spec/compiler/normalize/def_spec.cr index fb625a8d6a59..d0f9a3d89e7e 100644 --- a/spec/compiler/normalize/def_spec.cr +++ b/spec/compiler/normalize/def_spec.cr @@ -225,5 +225,11 @@ module Crystal other_def = a_def.expand_new_default_arguments(Program.new, 0, ["x", "y", "z"]) other_def.to_s.should eq("def new:x:y:z(x __temp_1, y __temp_2, z __temp_3)\n _ = allocate\n _.initialize(x: __temp_1, y: __temp_2, z: __temp_3)\n if _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\n end\n _\nend") end + + it "expands def with reserved external name (#6559)" do + a_def = parse("def foo(abstract __arg0, **options); @abstract = __arg0; end").as(Def) + other_def = a_def.expand_default_arguments(Program.new, 0, ["abstract"]) + other_def.to_s.should eq("def foo:abstract(abstract __arg0)\n options = {}\n @abstract = __arg0\nend") + end end end diff --git a/src/compiler/crystal/semantic/default_arguments.cr b/src/compiler/crystal/semantic/default_arguments.cr index 4be2509137ce..85112317edff 100644 --- a/src/compiler/crystal/semantic/default_arguments.cr +++ b/src/compiler/crystal/semantic/default_arguments.cr @@ -155,7 +155,7 @@ class Crystal::Def named_tuple_entries = [] of NamedTupleLiteral::Entry named_args.try &.each_with_index do |named_arg, i| # Don't put here regular arguments - next if args.any? &.name.==(named_arg) + next if args.any? &.external_name.==(named_arg) temp_name = named_args_temp_names.not_nil![i] named_tuple_entries << NamedTupleLiteral::Entry.new(named_arg, Var.new(temp_name))