Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error message for megaparametric functions could be better #10737

Closed
hrhino opened this issue Feb 20, 2018 · 15 comments
Closed

Error message for megaparametric functions could be better #10737

hrhino opened this issue Feb 20, 2018 · 15 comments

Comments

@hrhino
Copy link

hrhino commented Feb 20, 2018

scala> trait T { val x: (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z) => Int }
                                                                              ^
       error: type Function26 is not a member of package scala

Of course, FunctionXXL would be better (?) still, but something like scala/scala#4927 would be a nice touch.

@hrhino hrhino added the parser label Feb 20, 2018
@hrhino hrhino added this to the Backlog milestone Feb 20, 2018
@hrhino
Copy link
Author

hrhino commented Feb 21, 2018

  /** Create a tree representing the function type (argtpes) => restpe */
  def mkFunctionTypeTree(argtpes: List[Tree], restpe: Tree): Tree =
    AppliedTypeTree(rootScalaDot(newTypeName("Function" + argtpes.length)), argtpes ::: List(restpe))

should probably check before blindly making up a class name.

@Jasper-M
Copy link

should probably check before blindly making up a class name.

Or you could just make it up and then erase it to one that does exist afterwards.

@hrhino
Copy link
Author

hrhino commented Feb 21, 2018

Of course, FunctionXXL would be better (?) still

Right, I'd like to get the xxl functions (and tuples?) into scalac, but that's probably a SIP...

@LPTK
Copy link

LPTK commented Mar 7, 2018

Wow, this issue made me realize that you can actually take advantage of this "feature" of scalac to define your own functions beyond the 22 limit:

package scala {
  trait Function26[a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,R] {
    def apply(a:a,b:b,c:c,d:d,e:e,f:f,g:g,h:h,i:i,j:j,k:k,l:l,m:m,n:n,o:o,p:p,q:q,r:r,s:s,t:t,u:u,v:v,w:w,x:x,y:y,z:z): R
  }
}
package test {
  object Test {
    def foo(f: (Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int) => Int) = 
      f(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1)
  }
}

Hopefully no one is currently relying on this mechanism 😅

@jonathanfrawley
Copy link

Added a PR that addresses this : scala/scala#6401

Here is the error message it gives, which I think is an improvement:

func-max-args.scala:2: error: too many arguments for function: 26, allowed: 22
  val x: (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z) => Int
         ^
one error found 

@LPTK
Copy link

LPTK commented Mar 9, 2018

Wouldn't it be more precise to say: "26 given, maximum allowed: 22"

@hrhino
Copy link
Author

hrhino commented Mar 9, 2018

There's a precedent for the current wording, at least:

scala> (1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1)
<console>:1: error: too many elements for tuple: 25, allowed: 22
       (1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1)
       ^

I agree it could be better. "error: tuples (functions) may not have more than 22 elements (parameters), but 25 given" maybe.

@jonathanfrawley
Copy link

Yeah, I copied the tuple error text for consistency. Happy to change both of them to match that @hrhino

@jonathanfrawley
Copy link

Hmm, it seems like functions declared with "def" can have more than 22 parameters. Would something like this be better to distinguish it from that case?

error: function values may not have more than 22 elements (parameters), but 25 given

@hrhino
Copy link
Author

hrhino commented Mar 9, 2018

Technically def defines a method, not a function. I don't think that's less clear, though.

jonathanfrawley added a commit to jonathanfrawley/scala that referenced this issue Mar 9, 2018
 - Addresses scala/bug#10737
 - Also change tuple error messages to conform to new wording
@jonathanfrawley
Copy link

jonathanfrawley commented Mar 9, 2018

Okay, I have updated the tuple and function error messages to be as follows:

Tuples:

t9572.scala:3: error: tuples may not have more than 22 elements, but 23 given
  val term23 = (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23)
               ^
one error found

Functions:

func-max-args.scala:3: error: function values may not have more than 22 parameters, but 23 given
  val func23: (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w) => Int
              ^
one error found

I have cleaned up the code a bit and improved the test slightly as well. What do people think of this phrasing?

@SethTisue
Copy link
Member

What do people think of this phrasing?

👍

@jonathanfrawley
Copy link

I have made some updates on the PR (scala/scala#6401) based on feedback.
Here are the updated error messages:

Eta expansions:

t7299.scala:4: error: functions may not have more than 22 parameters
   val eta1 = f _
              ^
t7299.scala:5: error: functions may not have more than 22 parameters
   val eta2 = g[Any] _
               ^
two errors found

Functions:

t944.scala:5: error: functions may not have more than 22 parameters
           a23:Int) => 1
                    ^
one error found

Tuples:

t9572.scala:3: error: tuples may not have more than 22 elements, but 23 given
  val term23 = (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23)
                                                                         ^
t9572.scala:5: error: tuples may not have more than 22 elements, but 23 given
  val type23: (Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int) = null
                                                                                                       ^
two errors found

Function values:

func-max-args.scala:3: error: function values may not have more than 22 parameters, but 23 given
  val func23: (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w) => Int
                                                           ^
one error found

@hrhino hrhino added the has PR label Mar 14, 2018
@hrhino hrhino modified the milestones: Backlog, 2.13.0-M4 Mar 14, 2018
@SethTisue SethTisue modified the milestones: 2.13.0-M4, 2.13.0-M5 May 9, 2018
adriaanm pushed a commit to jonathanfrawley/scala that referenced this issue Jun 14, 2018
 - Addresses scala/bug#10737
 - Also change tuple error messages to conform to new wording
@SethTisue
Copy link
Member

@df3n5 after accepting my invite to https://github.com/orgs/scala/teams/contributors, comment here and I'll assign the ticket to you.

@jonathanfrawley
Copy link

@SethTisue I have accepted that invite now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants