-
Notifications
You must be signed in to change notification settings - Fork 21
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
Comments
/** 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. |
Or you could just make it up and then erase it to one that does exist afterwards. |
Right, I'd like to get the xxl functions (and tuples?) into scalac, but that's probably a SIP... |
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 😅 |
Added a PR that addresses this : scala/scala#6401 Here is the error message it gives, which I think is an improvement:
|
Wouldn't it be more precise to say: " |
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. |
Yeah, I copied the tuple error text for consistency. Happy to change both of them to match that @hrhino |
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?
|
Technically |
- Addresses scala/bug#10737 - Also change tuple error messages to conform to new wording
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? |
👍 |
I have made some updates on the PR (scala/scala#6401) based on feedback. 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 |
- Addresses scala/bug#10737 - Also change tuple error messages to conform to new wording
@df3n5 after accepting my invite to https://github.com/orgs/scala/teams/contributors, comment here and I'll assign the ticket to you. |
@SethTisue I have accepted that invite now. |
Of course,
FunctionXXL
would be better (?) still, but something like scala/scala#4927 would be a nice touch.The text was updated successfully, but these errors were encountered: