Skip to content

Commit

Permalink
Count size of parameters for platform limit check (#18464)
Browse files Browse the repository at this point in the history
Fixes #18458
  • Loading branch information
nicolasstucki authored Aug 28, 2023
2 parents 2616c8b + 0f62db9 commit 45f633d
Show file tree
Hide file tree
Showing 3 changed files with 217 additions and 2 deletions.
9 changes: 7 additions & 2 deletions compiler/src/dotty/tools/backend/jvm/BCodeSkelBuilder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -763,9 +763,14 @@ trait BCodeSkelBuilder extends BCodeHelpers {
for (p <- params) { locals.makeLocal(p.symbol) }
// debug assert((params.map(p => locals(p.symbol).tk)) == asmMethodType(methSymbol).getArgumentTypes.toList, "debug")

if (params.size > MaximumJvmParameters) {
val paramsSize = params.map { param =>
val tpeTym = param.symbol.info.typeSymbol
if tpeTym == defn.LongClass || tpeTym == defn.DoubleClass then 2 else 1
}.sum
if (paramsSize > MaximumJvmParameters) {
// SI-7324
report.error(em"Platform restriction: a parameter list's length cannot exceed $MaximumJvmParameters.", ctx.source.atSpan(methSymbol.span))
val info = if paramsSize == params.length then "" else " (Long and Double count as 2)" // https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.3.3
report.error(em"Platform restriction: a parameter list's length cannot exceed $MaximumJvmParameters$info.", ctx.source.atSpan(methSymbol.span))
return
}

Expand Down
4 changes: 4 additions & 0 deletions tests/neg/i18458.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Error: tests/neg/i18458.scala:1:4 -----------------------------------------------------------------------------------
1 |def foo( // error
| ^
| Platform restriction: a parameter list's length cannot exceed 254 (Long and Double count as 2).
206 changes: 206 additions & 0 deletions tests/neg/i18458.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
def foo( // error
foo1: Long,
foo2: Long,
foo3: Long,
foo4: Long,
foo5: Long,
foo6: Long,
foo7: Long,
foo8: Long,
foo9: Long,
foo10: Long,
foo11: Long,
foo12: Long,
foo13: Long,
foo14: Long,
foo15: Long,
foo16: Long,
foo17: Long,
foo18: Long,
foo19: Long,
foo20: Long,
foo21: Long,
foo22: Long,
foo23: Long,
foo24: Long,
foo25: Long,
foo26: Long,
foo27: Long,
foo28: Long,
foo29: Long,
foo30: Long,
foo31: Long,
foo32: Long,
foo33: Long,
foo34: Long,
foo35: Long,
foo36: Long,
foo37: Long,
foo38: Long,
foo39: Long,
foo40: Long,
foo41: Long,
foo42: Long,
foo43: Long,
foo44: Long,
foo45: Long,
foo46: Long,
foo47: Long,
foo48: Long,
foo49: Long,
foo50: Long,
foo51: Long,
foo52: Long,
foo53: Long,
foo54: Long,
foo55: Long,
foo56: Long,
foo57: Long,
foo58: Long,
foo59: Long,
foo60: Long,
foo61: Long,
foo62: Long,
foo63: Long,
foo64: Long,
foo65: Long,
foo66: Long,
foo67: Long,
foo68: Long,
foo69: Long,
foo70: Long,
foo71: Long,
foo72: Long,
foo73: Long,
foo74: Long,
foo75: Long,
foo76: Long,
foo77: Long,
foo78: Long,
foo79: Long,
foo80: Long,
foo81: Long,
foo82: Long,
foo83: Long,
foo84: Long,
foo85: Long,
foo86: Long,
foo87: Long,
foo88: Long,
foo89: Long,
foo90: Long,
foo91: Long,
foo92: Long,
foo93: Long,
foo94: Long,
foo95: Long,
foo96: Long,
foo97: Long,
foo98: Long,
foo99: Long,
foo100: Long,
foo101: Long,
foo102: Long,
foo103: Long,
foo104: Long,
foo105: Long,
foo106: Long,
foo107: Long,
foo108: Long,
foo109: Long,
foo110: Long,
foo111: Long,
foo112: Long,
foo113: Long,
foo114: Long,
foo115: Long,
foo116: Long,
foo117: Long,
foo118: Long,
foo119: Long,
foo120: Long,
foo121: Long,
foo122: Long,
foo123: Long,
foo124: Long,
foo125: Long,
foo126: Long,
foo127: Long,
foo128: Long,
foo129: Long,
foo130: Long,
foo131: Long,
foo132: Long,
foo133: Long,
foo134: Long,
foo135: Long,
foo136: Long,
foo137: Long,
foo138: Long,
foo139: Long,
foo140: Long,
foo141: Long,
foo142: Long,
foo143: Long,
foo144: Long,
foo145: Long,
foo146: Long,
foo147: Long,
foo148: Long,
foo149: Long,
foo150: Long,
foo151: Long,
foo152: Long,
foo153: Long,
foo154: Long,
foo155: Long,
foo156: Long,
foo157: Long,
foo158: Long,
foo159: Long,
foo160: Long,
foo161: Long,
foo162: Long,
foo163: Long,
foo164: Long,
foo165: Long,
foo166: Long,
foo167: Long,
foo168: Long,
foo169: Long,
foo170: Long,
foo171: Long,
foo172: Long,
foo173: Long,
foo174: Long,
foo175: Long,
foo176: Long,
foo177: Long,
foo178: Long,
foo179: Long,
foo180: Long,
foo181: Long,
foo182: Long,
foo183: Long,
foo184: Long,
foo185: Long,
foo186: Long,
foo187: Long,
foo188: Long,
foo189: Long,
foo190: Long,
foo191: Long,
foo192: Long,
foo193: Long,
foo194: Long,
foo195: Long,
foo196: Long,
foo197: Long,
foo198: Long,
foo199: Long,
foo200: Long
) = foo1 + foo2

@main
def run =
println(foo(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200))

0 comments on commit 45f633d

Please sign in to comment.