Skip to content

Commit

Permalink
Disallow duplicate fun parameter names (#11967)
Browse files Browse the repository at this point in the history
  • Loading branch information
HertzDevil committed Jun 1, 2022
1 parent d28488c commit 9b8870c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
3 changes: 3 additions & 0 deletions spec/compiler/parser/parser_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -1806,6 +1806,9 @@ module Crystal
assert_syntax_error "def foo(**x, &x); end", "duplicated def parameter name: x"
assert_syntax_error "def foo(x, **x); end", "duplicated def parameter name: x"

assert_syntax_error "fun foo(x : Int32, x : Int64); end", "duplicated fun parameter name: x"
assert_syntax_error "lib Foo; fun foo(x : Int32, x : Int64); end", "duplicated fun parameter name: x"

assert_syntax_error "Set {1, 2, 3} of Int32"
assert_syntax_error "Hash {foo: 1} of Int32 => Int32"
assert_syntax_error "enum Foo < UInt16; end"
Expand Down
4 changes: 2 additions & 2 deletions src/big/lib_gmp.cr
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ lib LibGMP
# # Conversion
fun mpf_get_str = __gmpf_get_str(str : UInt8*, expptr : MpExp*, base : Int, n_digits : LibC::SizeT, op : MPF*) : UInt8*
fun mpf_get_d = __gmpf_get_d(op : MPF*) : Double
fun mpf_set_d = __gmpf_set_d(op : MPF*, op : Double)
fun mpf_set = __gmpf_set(op : MPF*, op : MPF*)
fun mpf_set_d = __gmpf_set_d(rop : MPF*, op : Double)
fun mpf_set = __gmpf_set(rop : MPF*, op : MPF*)
fun mpf_set_z = __gmpf_set_z(rop : MPF*, op : MPZ*)
fun mpf_set_q = __gmpf_set_q(rop : MPF*, op : MPQ*)
fun mpf_get_si = __gmpf_get_si(op : MPF*) : SI
Expand Down
6 changes: 6 additions & 0 deletions src/compiler/crystal/syntax/parser.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5643,6 +5643,12 @@ module Crystal
arg_type = parse_bare_proc_type
skip_space_or_newline

args.each do |arg|
if arg.name == arg_name
raise "duplicated fun parameter name: #{arg_name}", arg_location
end
end

args << Arg.new(arg_name, nil, arg_type).at(arg_location)

push_var_name arg_name if require_body
Expand Down

0 comments on commit 9b8870c

Please sign in to comment.