Skip to content

Crash regarding F-bounded identity alias #20317

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

Open
s5bug opened this issue May 1, 2024 · 1 comment
Open

Crash regarding F-bounded identity alias #20317

s5bug opened this issue May 1, 2024 · 1 comment

Comments

@s5bug
Copy link

s5bug commented May 1, 2024

Compiler version

3.4.1, 3.4.2-RC1

Minimized code

type Foo[A] = A

def foo[A <: Foo[A]]: Unit = ()

Output (click arrow to expand)

3.4.2-RC1:

java.lang.AssertionError: assertion failed: NoType
	at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
	at dotty.tools.dotc.core.Types$TypeBounds.&lt;init&gt;(Types.scala:5493)
	at dotty.tools.dotc.core.Types$AliasingBounds.&lt;init&gt;(Types.scala:5572)
	at dotty.tools.dotc.core.Types$TypeAlias.&lt;init&gt;(Types.scala:5596)
	at dotty.tools.dotc.core.Types$TypeAlias$.apply(Types.scala:5633)
	at dotty.tools.dotc.core.Types$Type.bounds(Types.scala:1813)
	at dotty.tools.dotc.core.GadtState.$anonfun$4$$anonfun$1(GadtConstraint.scala:197)
	at scala.collection.immutable.List.map(List.scala:246)
	at dotty.tools.dotc.core.GadtState.$anonfun$4(GadtConstraint.scala:201)
	at dotty.tools.dotc.core.Types$PolyType.&lt;init&gt;(Types.scala:4333)
	at dotty.tools.dotc.core.Types$PolyType$.apply(Types.scala:4439)
	at dotty.tools.dotc.core.GadtState.addToConstraint(GadtConstraint.scala:204)
	at dotty.tools.dotc.core.GadtState.addToConstraint$(GadtConstraint.scala:156)
	at dotty.tools.dotc.core.ProperGadtState.addToConstraint(GadtConstraint.scala:289)
	at dotty.tools.dotc.typer.Typer.typedDefDef(Typer.scala:2619)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3119)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3220)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3298)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3302)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3324)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3370)
	at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2814)
	at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$1(Typer.scala:3125)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3129)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3220)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3298)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3302)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3324)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3370)
	at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:2947)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3171)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3221)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3298)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3302)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3413)
	at dotty.tools.dotc.typer.TyperPhase.typeCheck$$anonfun$1(TyperPhase.scala:47)
	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
	at dotty.tools.dotc.core.Phases$Phase.monitor(Phases.scala:477)
	at dotty.tools.dotc.typer.TyperPhase.typeCheck(TyperPhase.scala:53)
	at dotty.tools.dotc.typer.TyperPhase.$anonfun$4(TyperPhase.scala:99)
	at scala.collection.Iterator$$anon$6.hasNext(Iterator.scala:479)
	at scala.collection.Iterator$$anon$9.hasNext(Iterator.scala:583)
	at scala.collection.immutable.List.prependedAll(List.scala:152)
	at scala.collection.immutable.List$.from(List.scala:684)
	at scala.collection.immutable.List$.from(List.scala:681)
	at scala.collection.IterableOps$WithFilter.map(Iterable.scala:898)
	at dotty.tools.dotc.typer.TyperPhase.runOn(TyperPhase.scala:100)
	at dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:315)
	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
	at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323)
	at dotty.tools.dotc.Run.runPhases$1(Run.scala:337)
	at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:350)
	at dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:360)
	at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:69)
	at dotty.tools.dotc.Run.compileUnits(Run.scala:360)
	at dotty.tools.dotc.Run.compileSources(Run.scala:261)
	at dotty.tools.dotc.Run.compile(Run.scala:246)
	at dotty.tools.dotc.Driver.doCompile(Driver.scala:37)
	at dotty.tools.xsbt.CompilerBridgeDriver.run(CompilerBridgeDriver.java:141)
	at dotty.tools.xsbt.CompilerBridge.run(CompilerBridge.java:22)
	at sbt.internal.inc.AnalyzingCompiler.compile(AnalyzingCompiler.scala:91)
	at sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$7(MixedAnalyzingCompiler.scala:193)
	at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
	at sbt.internal.inc.MixedAnalyzingCompiler.timed(MixedAnalyzingCompiler.scala:248)
	at sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4(MixedAnalyzingCompiler.scala:183)
	at sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4$adapted(MixedAnalyzingCompiler.scala:163)
	at sbt.internal.inc.JarUtils$.withPreviousJar(JarUtils.scala:239)
	at sbt.internal.inc.MixedAnalyzingCompiler.compileScala$1(MixedAnalyzingCompiler.scala:163)
	at sbt.internal.inc.MixedAnalyzingCompiler.compile(MixedAnalyzingCompiler.scala:211)
	at sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1(IncrementalCompilerImpl.scala:534)
	at sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1$adapted(IncrementalCompilerImpl.scala:534)
	at sbt.internal.inc.Incremental$.$anonfun$apply$5(Incremental.scala:180)
	at sbt.internal.inc.Incremental$.$anonfun$apply$5$adapted(Incremental.scala:178)
	at sbt.internal.inc.Incremental$$anon$2.run(Incremental.scala:464)
	at sbt.internal.inc.IncrementalCommon$CycleState.next(IncrementalCommon.scala:116)
	at sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:56)
	at sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:52)
	at sbt.internal.inc.IncrementalCommon.cycle(IncrementalCommon.scala:263)
	at sbt.internal.inc.Incremental$.$anonfun$incrementalCompile$8(Incremental.scala:419)
	at sbt.internal.inc.Incremental$.withClassfileManager(Incremental.scala:506)
	at sbt.internal.inc.Incremental$.incrementalCompile(Incremental.scala:406)
	at sbt.internal.inc.Incremental$.apply(Incremental.scala:172)
	at sbt.internal.inc.IncrementalCompilerImpl.compileInternal(IncrementalCompilerImpl.scala:534)
	at sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileIncrementally$1(IncrementalCompilerImpl.scala:488)
	at sbt.internal.inc.IncrementalCompilerImpl.handleCompilationError(IncrementalCompilerImpl.scala:332)
	at sbt.internal.inc.IncrementalCompilerImpl.compileIncrementally(IncrementalCompilerImpl.scala:425)
	at sbt.internal.inc.IncrementalCompilerImpl.compile(IncrementalCompilerImpl.scala:137)
	at sbt.Defaults$.compileIncrementalTaskImpl(Defaults.scala:2371)
	at sbt.Defaults$.$anonfun$compileIncrementalTask$2(Defaults.scala:2321)
	at sbt.internal.server.BspCompileTask$.$anonfun$compute$1(BspCompileTask.scala:31)
	at sbt.internal.io.Retry$.apply(Retry.scala:47)
	at sbt.internal.io.Retry$.apply(Retry.scala:29)
	at sbt.internal.io.Retry$.apply(Retry.scala:24)
	at sbt.internal.server.BspCompileTask$.compute(BspCompileTask.scala:31)
	at sbt.Defaults$.$anonfun$compileIncrementalTask$1(Defaults.scala:2319)
	at scala.Function1.$anonfun$compose$1(Function1.scala:49)
	at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:63)
	at sbt.std.Transform$$anon$4.work(Transform.scala:69)
	at sbt.Execute.$anonfun$submit$2(Execute.scala:283)
	at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:24)
	at sbt.Execute.work(Execute.scala:292)
	at sbt.Execute.$anonfun$submit$1(Execute.scala:283)
	at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:265)
	at sbt.CompletionService$$anon$2.call(CompletionService.scala:65)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.lang.Thread.run(Thread.java:840)

etc

I minimized this from

type SemigroupStructural[A] =
  A & { def combine(a: A): A }
def combineAll[A <: SemigroupStructural[A]](
  i: A, l: List[A]
): A = l.foldLeft(i)(_.combine(_))

which also crashes (but differently, due to a stack overflow) rather than producing a compile error.

Unfortunately I lack scalac on this current computer and I can't figure out how to get Scastie to give me a real stacktrace:

Recursion limit exceeded.
Maybe there is an illegal cyclic reference?
If that's not the case, you could also try to increase the stacksize using the -Xss JVM option.
For the unprocessed stack trace, compile with -Yno-decode-stacktraces.
A recurring operation is (inner to outer):

  subtype (i : A) <:< B
  subtype (i : A) <:< B
@s5bug s5bug added itype:bug itype:crash stat:needs triage Every issue needs to have an "area" and "itype" label labels May 1, 2024
@odersky odersky linked a pull request May 2, 2024 that will close this issue
@jchyb jchyb removed a link to a pull request May 6, 2024
@Gedochao
Copy link
Contributor

Gedochao commented May 9, 2024

On the latest nightly the output changes to:

-- Error: /Users/pchabelski/IdeaProjects/scala-cli-tests/compiler-repro/repro.scala:3:10 
3 |def foo[A <: Foo[A]]: Unit = ()
  |          ^
  |Recursion limit exceeded.
  |Maybe there is an illegal cyclic reference?
  |If that's not the case, you could also try to increase the stacksize using the -Xss JVM option.
  |For the unprocessed stack trace, compile with -Xno-decode-stacktraces.
  |A recurring operation is (inner to outer):
  |
  |  type parameters of Foo[A]
  |  type parameters of  <: Foo[A]
  |  type parameters of A
  |  type parameters of A
  |  type parameters of Foo[A]
  |  type parameters of  <: Foo[A]
  |  type parameters of A
  |  type parameters of A
  |  type parameters of Foo[A]
  |  type parameters of  <: Foo[A]
  |  ...
  |
  |  type parameters of A
  |  type parameters of Foo[A]
  |  type parameters of  <: Foo[A]
  |  type parameters of A
  |  type parameters of A
  |  type parameters of Foo[A]
  |  type parameters of  <: Foo[A]
  |  type parameters of A
  |  type parameters of Foo[A]
  |  type parameters of  <: Foo[A]
1 error found

@Gedochao Gedochao added area:typer and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels May 9, 2024
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

2 participants