Scala Programming Language
  1. Scala Programming Language
  2. SI-4928

Wrong compiler error message with default parameters when specifying a nonexistent named parameter

    Details

      Description

      When calling a method using named arguments, if the method has an argument with a default value which is not specified, but another (nonexistent) parameter is specified, the compiler gives the error "parameter specified twice" instead of "not found". This is confusing and misleading:

      scala> def x(a:Int,b:Int,c:Int,d:Int = 0) = println(a,b,c,d)
      x: (a: Int, b: Int, c: Int, d: Int)Unit
      
      scala> x(a=1,b=2,c=3)
      (1,2,3,0)
      
      scala> x(z=0,a=1,b=2,c=3)
      <console>:9: error: parameter specified twice: a
             x(z=0,a=1,b=2,c=3)
                    ^
      
      scala> x(z=1,b=2,c=3,d=4)
      <console>:9: error: not found: value z
             x(z=1,b=2,c=3,d=4)
               ^
      

        Issue Links

          Activity

          Hide
          Hubert Plociniczak added a comment -

          I will take it, errors took a couple of weeks of my life already so yet another bug wouldn't make a difference.

          Show
          Hubert Plociniczak added a comment - I will take it, errors took a couple of weeks of my life already so yet another bug wouldn't make a difference.
          Show
          Lukas Rytz added a comment - better error message since https://github.com/scala/scala/commit/3c79caa1369a7c1794097b669859118a71ab015e

            People

            • Assignee:
              Lukas Rytz
              Reporter:
              Mario Camou
            • Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development