question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Compiler crashes when `util.Random.shuffle(???)`

See original GitHub issue

Compiler version

3.1.0-RC3

Minimized code

In REPL :

sbt> consoleQuick
Welcome to Scala 3.1.0-RC3 (11.0.11, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.
                                                                                                                                            
scala> util.Random.shuffle(???)

Output

[error] (run-main-1) java.util.NoSuchElementException: head of empty list
[error] java.util.NoSuchElementException: head of empty list
[error] 	at scala.collection.immutable.Nil$.head(List.scala:662)
[error] 	at scala.collection.immutable.Nil$.head(List.scala:661)
[error] 	at dotty.tools.dotc.core.SymDenotations$SymDenotation.recurWithParamss$1(SymDenotations.scala:312)
[error] 	at dotty.tools.dotc.core.SymDenotations$SymDenotation.recurWithParamss$1(SymDenotations.scala:312)
[error] 	at dotty.tools.dotc.core.SymDenotations$SymDenotation.recurWithParamss$1(SymDenotations.scala:312)
[error] 	at dotty.tools.dotc.core.SymDenotations$SymDenotation.paramSymss(SymDenotations.scala:329)
[error] 	at dotty.tools.dotc.typer.Typer.paramSymWithMethodTree$3(Typer.scala:3403)
[error] 	at dotty.tools.dotc.typer.Typer.issueErrors$1$$anonfun$1$$anonfun$1(Typer.scala:3415)
[error] 	at dotty.tools.dotc.reporting.NoExplanation.msg(Message.scala:132)
[error] 	at dotty.tools.dotc.reporting.Message.message(Message.scala:87)
[error] 	at dotty.tools.dotc.reporting.Message.isNonSensical(Message.scala:99)
[error] 	at dotty.tools.dotc.reporting.HideNonSensicalMessages.isHidden(HideNonSensicalMessages.scala:16)
[error] 	at dotty.tools.dotc.reporting.HideNonSensicalMessages.isHidden$(HideNonSensicalMessages.scala:10)
[error] 	at dotty.tools.repl.package$$anon$1.isHidden(package.scala:8)
[error] 	at dotty.tools.dotc.reporting.Reporter.go$3$$anonfun$2(Reporter.scala:161)
[error] 	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[error] 	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[error] 	at scala.Option.foreach(Option.scala:437)
[error] 	at dotty.tools.dotc.reporting.Reporter.go$1(Reporter.scala:174)
[error] 	at dotty.tools.dotc.reporting.Reporter.issueIfNotSuppressed(Reporter.scala:193)
[error] 	at dotty.tools.dotc.reporting.Reporter.report(Reporter.scala:196)
[error] 	at dotty.tools.dotc.report$.error(report.scala:63)
[error] 	at dotty.tools.dotc.typer.Typer.issueErrors$2$$anonfun$2(Typer.scala:3417)
[error] 	at scala.runtime.function.JProcedure3.apply(JProcedure3.java:15)
[error] 	at scala.runtime.function.JProcedure3.apply(JProcedure3.java:10)
[error] 	at scala.collection.LazyZip3.foreach(LazyZipOps.scala:248)
[error] 	at dotty.tools.dotc.typer.Typer.issueErrors$3(Typer.scala:3419)
[error] 	at dotty.tools.dotc.typer.Typer.addImplicitArgs$3(Typer.scala:3445)
[error] 	at dotty.tools.dotc.typer.Typer.adaptNoArgsImplicitMethod$2(Typer.scala:3462)
[error] 	at dotty.tools.dotc.typer.Typer.adaptNoArgs$1(Typer.scala:3660)
[error] 	at dotty.tools.dotc.typer.Typer.adapt1(Typer.scala:3873)
[error] 	at dotty.tools.dotc.typer.Typer.adapt(Typer.scala:3224)
[error] 	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2883)
[error] 	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2887)
[error] 	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3003)
[error] 	at dotty.tools.dotc.typer.Namer.typedAheadExpr$$anonfun$1(Namer.scala:1429)
[error] 	at dotty.tools.dotc.typer.Namer.typedAhead(Namer.scala:1419)
[error] 	at dotty.tools.dotc.typer.Namer.typedAheadExpr(Namer.scala:1429)
[error] 	at dotty.tools.dotc.typer.Namer.typedAheadRhs$1$$anonfun$1(Namer.scala:1681)
[error] 	at dotty.tools.dotc.typer.PrepareInlineable$.dropInlineIfError(PrepareInlineable.scala:225)
[error] 	at dotty.tools.dotc.typer.Namer.typedAheadRhs$2(Namer.scala:1681)
[error] 	at dotty.tools.dotc.typer.Namer.rhsType$1(Namer.scala:1689)
[error] 	at dotty.tools.dotc.typer.Namer.cookedRhsType$1(Namer.scala:1716)
[error] 	at dotty.tools.dotc.typer.Namer.lhsType$1(Namer.scala:1717)
[error] 	at dotty.tools.dotc.typer.Namer.inferredResultType(Namer.scala:1728)
[error] 	at dotty.tools.dotc.typer.Namer.inferredType$1(Namer.scala:1468)
[error] 	at dotty.tools.dotc.typer.Namer.valOrDefDefSig(Namer.scala:1475)
[error] 	at dotty.tools.dotc.typer.Namer$Completer.typeSig(Namer.scala:751)
[error] 	at dotty.tools.dotc.typer.Namer$Completer.completeInCreationContext(Namer.scala:887)
[error] 	at dotty.tools.dotc.typer.Namer$Completer.complete(Namer.scala:779)
[error] 	at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:167)
[error] 	at dotty.tools.dotc.core.Denotations$Denotation.completeInfo$1(Denotations.scala:188)
[error] 	at dotty.tools.dotc.core.Denotations$Denotation.info(Denotations.scala:190)
[error] 	at dotty.tools.dotc.core.SymDenotations$SymDenotation.ensureCompleted(SymDenotations.scala:369)
[error] 	at dotty.tools.dotc.typer.Typer.retrieveSym(Typer.scala:2697)
[error] 	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2722)
[error] 	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2817)
[error] 	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2883)
[error] 	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2887)
[error] 	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2909)
[error] 	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2959)
[error] 	at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2409)
[error] 	at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$2(Typer.scala:2743)
[error] 	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2747)
[error] 	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2817)
[error] 	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2883)
[error] 	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2887)
[error] 	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2909)
[error] 	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2959)
[error] 	at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:2532)
[error] 	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2788)
[error] 	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2818)
[error] 	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2883)
[error] 	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2887)
[error] 	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3003)
[error] 	at dotty.tools.dotc.typer.TyperPhase.liftedTree1$1(TyperPhase.scala:56)
[error] 	at dotty.tools.dotc.typer.TyperPhase.typeCheck$$anonfun$1(TyperPhase.scala:62)
[error] 	at dotty.tools.dotc.core.Phases$Phase.monitor(Phases.scala:411)
[error] 	at dotty.tools.dotc.typer.TyperPhase.typeCheck(TyperPhase.scala:63)
[error] 	at dotty.tools.dotc.typer.TyperPhase.runOn$$anonfun$1(TyperPhase.scala:105)
[error] 	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[error] 	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[error] 	at scala.collection.immutable.List.foreach(List.scala:333)
[error] 	at dotty.tools.dotc.typer.TyperPhase.runOn(TyperPhase.scala:105)
[error] 	at dotty.tools.dotc.Run.runPhases$4$$anonfun$4(Run.scala:261)
[error] 	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[error] 	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[error] 	at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323)
[error] 	at dotty.tools.dotc.Run.runPhases$5(Run.scala:272)
[error] 	at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:280)
[error] 	at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
[error] 	at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:68)
[error] 	at dotty.tools.dotc.Run.compileUnits(Run.scala:289)
[error] 	at dotty.tools.dotc.Run.compileUnits(Run.scala:228)
[error] 	at dotty.tools.repl.ReplCompiler.runCompilationUnit(ReplCompiler.scala:155)
[error] 	at dotty.tools.repl.ReplCompiler.compile(ReplCompiler.scala:165)
[error] 	at dotty.tools.repl.ReplDriver.compile(ReplDriver.scala:250)
[error] 	at dotty.tools.repl.ReplDriver.interpret(ReplDriver.scala:218)
[error] 	at dotty.tools.repl.ReplDriver.loop$1(ReplDriver.scala:152)
[error] 	at dotty.tools.repl.ReplDriver.runUntilQuit$$anonfun$1(ReplDriver.scala:155)
[error] 	at dotty.tools.repl.ReplDriver.withRedirectedOutput(ReplDriver.scala:174)
[error] 	at dotty.tools.repl.ReplDriver.runUntilQuit(ReplDriver.scala:155)
[error] 	at xsbt.ConsoleInterface.run(ConsoleInterface.java:52)
[error] 	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[error] 	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[error] 	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[error] 	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
[error] 	at sbt.internal.inc.AnalyzingCompiler.invoke(AnalyzingCompiler.scala:329)
[error] 	at sbt.internal.inc.AnalyzingCompiler.console(AnalyzingCompiler.scala:233)
[error] 	at sbt.Console.console0$1(Console.scala:64)
[error] 	at sbt.Console.$anonfun$apply$5(Console.scala:74)
[error] 	at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
[error] 	at sbt.util.InterfaceUtil$$anon$1.get(InterfaceUtil.scala:17)
[error] 	at sbt.TrapExit$App.run(TrapExit.scala:258)
[error] 	at java.base/java.lang.Thread.run(Thread.java:829)

The same crash if a value of an unknown type is given.

Expectation

The compiler should give an error message.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

0reactions
KacperFKorbancommented, Oct 15, 2021

Since this bug wasn’t introduced in 3.1.0-RC, it most likely will not be backported.

Read more comments on GitHub >

github_iconTop Results From Across the Web

random.shuffle crashes when passed a range ...
shuffle returns None , since it actually shuffles a list in place. You could also use the list comprehension that Alvin McNair suggested,...
Read more >
C++ Random Number Causing Crash when printing out value ...
My issues is that the program will randomly crash when I try and print out the value generated by (dRandNum % 10).
Read more >
Knuth shuffle - Rosetta Code
The Knuth shuffle (a.k.a. the Fisher-Yates shuffle) is an algorithm for randomly shuffling the elements of an array. Task Implement the Knuth shuffle...
Read more >
Changelog — Python 3.11.1 documentation
gh-97728: Fix possible crashes caused by the use of uninitialized variables when pass invalid arguments in os.system() on Windows and in Windows-specific ...
Read more >
Why is this crashing the compiler 5.6 & 5.7? - Swift Forums
I'm trying to resolve UI from structured data. There is a "resolver" that maps content into a view, or falls back to the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found