Skip to content

Compiler crashes when util.Random.shuffle(???) #13754

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

Closed
bjornregnell opened this issue Oct 15, 2021 · 5 comments
Closed

Compiler crashes when util.Random.shuffle(???) #13754

bjornregnell opened this issue Oct 15, 2021 · 5 comments

Comments

@bjornregnell
Copy link
Contributor

bjornregnell commented Oct 15, 2021

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.

@bjornregnell
Copy link
Contributor Author

The crash seems to be similar to #12991 but I'm not sure if it is the same underlying problem.

@bjornregnell
Copy link
Contributor Author

Seems to be solved in current nightly, where the compiler survives:

sbt> consoleQuick
Welcome to Scala 3.1.1-RC1-bin-20211014-af9594d-NIGHTLY-git-af9594d (11.0.11, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.
                                                                                                                                            
scala> util.Random.shuffle(???)
-- Error: ----------------------------------------------------------------------
1 |util.Random.shuffle(???)
  |                        ^
  |ambiguous implicit arguments: both getter buildFromString in object BuildFrom and method buildFromView in object BuildFrom match type scala.collection.BuildFrom[(?1 : Nothing), T, C] of parameter bf of method shuffle in class Random
1 error found
                                                                                                                                            
scala> 

@bjornregnell
Copy link
Contributor Author

The release candidate 3.1.0-RC3 still crashes. Will the nightly fix be included in the final release of 3.1.0 ? Or should I close this?

@bjornregnell bjornregnell reopened this Oct 15, 2021
@KacperFKorban
Copy link
Member

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

@som-snytt
Copy link
Contributor

duplicates #12455
fixed under #13238

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

3 participants