Skip to content
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

Assertion failure on some illegal code with recursive type definition #9652

Closed
scabug opened this issue Feb 11, 2016 · 7 comments
Closed

Assertion failure on some illegal code with recursive type definition #9652

scabug opened this issue Feb 11, 2016 · 7 comments

Comments

@scabug
Copy link

scabug commented Feb 11, 2016

I got this assertion failure when, in ChangeStruct, I tried to add a type member mirroring the type parameter T, without renaming it.

Not very high priority I guess, since the crash follows a valid type error, but I thought I should file an issue anyway.

object IlcWithState {
  trait ChangeStruct[T] {
    type T = T
    type DT
    def oplus(a: T, da: DT): T
  }

  trait Fun2[T1, T2, R] {
    val T1: ChangeStruct[T1]
    val T2: ChangeStruct[T2]
    val R: ChangeStruct[R]
    type Cache
    def apply(x1: T1, x2: T2): (R, Cache)
    def dapply(dx1: T1.DT, dx2: T2.DT)(c: Cache): (R.DT, Cache)
  }


  //type IntChange = ChangeStruct { type T = Int; type DT = Int }
  trait IntChange extends ChangeStruct[Int] { type DT = Int }
  val IntChange: IntChange =
    new IntChange {
      def oplus(a: T, da: T): T = a + da
    }


  // Actually implementing the Fun2 interface is insane.
  val Div: Fun2[Int, Int, Int] {val T1: IntChange.type; val T2: IntChange.type; val R: IntChange.type} =
    new Fun2 {
      val T1: IntChange.type = IntChange
      val T2: IntChange.type = IntChange
      val R: IntChange.type = IntChange
      type Cache = (Int, Int)
      def apply(num: Int, den: Int) = (num / den, (num, den))
      def dapply(dnum: Int, dden: Int)(c: Cache) = {
        val (num, den) = c
        val num2 = T1.oplus(num, dnum)
        val den2 = T1.oplus(den, dden)
        (num2 / den2, (num2, den2))
      }
    }
  Div(2, 3)

}
[info] Compiling 1 Scala source to /Users/pgiarrusso/AeroFS/Repos/ilc-ldiff-bluevelvet/scala-stateful-ilc/target/scala-2.11/classes...
[error] /Users/pgiarrusso/AeroFS/Repos/ilc-ldiff-bluevelvet/scala-stateful-ilc/IlcWithState.scala:3: illegal cyclic reference involving type T
[error]     type T = T
[error]              ^
[error] /Users/pgiarrusso/AeroFS/Repos/ilc-ldiff-bluevelvet/scala-stateful-ilc/IlcWithState.scala:22: type mismatch;
[error]  found   : a.type (with underlying type this.T)
[error]  required: ?{def +(x$1: ? >: this.T): ?}
[error]     (which expands to)  ?{def +(x$1: ? >: <error>): ?}
[error] Note that implicit conversions are not applicable because they are ambiguous:
[error]  both method unaugmentString in object Predef of type (x: scala.collection.immutable.StringOps)String
[error]  and method Byte2byte in object Predef of type (x: Byte)Byte
[error]  are possible conversion functions from a.type to ?{def +(x$1: ? >: this.T): ?}
[error]       def oplus(a: T, da: T): T = a + da
[error]                                   ^
[error] /Users/pgiarrusso/AeroFS/Repos/ilc-ldiff-bluevelvet/scala-stateful-ilc/IlcWithState.scala:28: trait Fun2 takes type parameters
[error]     new Fun2 {
[error]         ^
[error] /Users/pgiarrusso/AeroFS/Repos/ilc-ldiff-bluevelvet/scala-stateful-ilc/IlcWithState.scala:38: type mismatch;
[error]  found   : num2.type (with underlying type this.T1.T)
[error]  required: ?{def /(x$1: ? >: this.T1.T): ?}
[error]     (which expands to)  ?{def /(x$1: ? >: <error>): ?}
[error] Note that implicit conversions are not applicable because they are ambiguous:
[error]  both method Byte2byte in object Predef of type (x: Byte)Byte
[error]  and method Short2short in object Predef of type (x: Short)Short
[error]  are possible conversion functions from num2.type to ?{def /(x$1: ? >: this.T1.T): ?}
[error]         (num2 / den2, (num2, den2))
[error]          ^
[error] /Users/pgiarrusso/AeroFS/Repos/ilc-ldiff-bluevelvet/scala-stateful-ilc/IlcWithState.scala:38: value / is not a member of this.T1.T
[error]         (num2 / den2, (num2, den2))
[error]               ^
[trace] Stack trace suppressed: run 'last compile:compileIncremental' for the full output.
[error] (compile:compileIncremental) java.lang.AssertionError: assertion failed: 
[error]   (AnyRef{val T1: IlcWithState.IntChange.type; val T1: IlcWithState.IntChange.type; val T2: IlcWithState.IntChange.type; val T2: IlcWithState.IntChange.type; val R: IlcWithState.IntChange.type; val R: IlcWithState.IntChange.type; type Cache = (Int, Int); def apply(num: Int,den: Int): (Int, (Int, Int)); def dapply(dnum: Int,dden: Int)(c: this.Cache): <error>},IlcWithState.Fun2[Int,Int,Int]{val T1: IlcWithState.IntChange.type; val T2: IlcWithState.IntChange.type; val R: IlcWithState.IntChange.type})
[error]      while compiling: /Users/pgiarrusso/AeroFS/Repos/ilc-ldiff-bluevelvet/scala-stateful-ilc/IlcWithState.scala
[error]         during phase: typer
[error]      library version: version 2.11.7
[error]     compiler version: version 2.11.7
[error]   reconstructed args: -classpath /Users/pgiarrusso/AeroFS/Repos/ilc-ldiff-bluevelvet/scala-stateful-ilc/target/scala-2.11/classes -bootclasspath /Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home/jre/lib/resources.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home/jre/lib/rt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home/jre/lib/sunrsasign.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home/jre/lib/jsse.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home/jre/lib/jce.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home/jre/lib/jfr.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home/jre/classes:/Users/pgiarrusso/.ivy2/cache/org.scala-lang/scala-library/jars/scala-library-2.11.7.jar
[error] 
[error]   last tree to typer: Select(New, <init>)
[error]        tree position: line 28 of /Users/pgiarrusso/AeroFS/Repos/ilc-ldiff-bluevelvet/scala-stateful-ilc/IlcWithState.scala
[error]             tree tpe: ()AnyRef{val T1: IlcWithState.IntChange.type; val T1: IlcWithState.IntChange.type; val T2: IlcWithState.IntChange.type; val T2: IlcWithState.IntChange.type; val R: IlcWithState.IntChange.type; val R: IlcWithState.IntChange.type; type Cache = (Int, Int); def apply(num: Int,den: Int): (Int, (Int, Int)); def dapply(dnum: Int,dden: Int)(c: this.Cache): <error>}
[error]               symbol: constructor $anon
[error]    symbol definition: def <init>(): $anon (a MethodSymbol)
[error]       symbol package: <empty>
[error]        symbol owners: constructor $anon -> <$anon: AnyRef> -> value Div -> object IlcWithState
[error]            call site: object IlcWithState in package <empty>
[error] 
[error] == Source file context for tree position ==
[error] 
[error]     25   // Actually implementing the Fun2 interface is insane.
[error]     26   val Div: Fun2[Int, Int, Int] {val T1: IntChange.type; val T2: IntChange.type; val R: IntChange.type} =
[error]     27     new Fun2 {
[error]     28       val T1: IntChange.type = IntChange
[error]     29       val T2: IntChange.type = IntChange
[error]     30       val R: IntChange.type = IntChange
[error]     31       type Cache = (Int, Int)
[error] Total time: 0 s, completed Feb 11, 2016 2:06:53 AM
> 
@scabug
Copy link
Author

scabug commented Feb 11, 2016

Imported From: https://issues.scala-lang.org/browse/SI-9652?orig=1
Reporter: @Blaisorblade
Affected Versions: 2.11.7
See #9361

@scabug
Copy link
Author

scabug commented Feb 11, 2016

@retronym said:
I'd wager that fixing #9361 will also fix this one.

@scabug
Copy link
Author

scabug commented Feb 11, 2016

@retronym said:
Here's the stack trace. (When reporting bugs through SBT, run last to see the suppressed stack trace)

    25   // Actually implementing the Fun2 interface is insane.
    26   val Div: Fun2[Int, Int, Int] {val T1: IntChange.type; val T2: IntChange.type; val R: IntChange.type} =
    27     new Fun2 {
    28       val T1: IntChange.type = IntChange
    29       val T2: IntChange.type = IntChange
    30       val R: IntChange.type = IntChange
    31       type Cache = (Int, Int)
	at scala.tools.nsc.typechecker.ContextErrors$TyperContextErrors$TyperErrorGen$.AdaptTypeError(ContextErrors.scala:216)
	at scala.tools.nsc.typechecker.Typers$Typer.adaptMismatchedSkolems$1(Typers.scala:1017)
	at scala.tools.nsc.typechecker.Typers$Typer.fallbackAfterVanillaAdapt$1(Typers.scala:1086)
	at scala.tools.nsc.typechecker.Typers$Typer.vanillaAdapt$1(Typers.scala:1123)
	at scala.tools.nsc.typechecker.Typers$Typer.adapt(Typers.scala:1166)
	at scala.tools.nsc.typechecker.Typers$Typer.runTyper$1(Typers.scala:5410)
	at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedInternal(Typers.scala:5423)
	at scala.tools.nsc.typechecker.Typers$Typer.body$2(Typers.scala:5370)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5374)
	at scala.tools.nsc.typechecker.Typers$Typer.typedBlock(Typers.scala:2382)

@Blaisorblade
Copy link

Unlikely to be fixed in Scala 2, it's a crash but with little impact...

@milessabin
Copy link

Despite #9361 being fixed, this still crashes in 2.13.0-M3, but slightly differently. Granted a fix for this is low priority, but I really don't see that that justifies closing this.

@milessabin milessabin reopened this Mar 3, 2018
@joroKr21
Copy link
Member

Doesn't crash since 2.13.0. Worth adding a regression test?

@SethTisue SethTisue modified the milestones: Backlog, 2.13.0 Dec 30, 2019
@SethTisue
Copy link
Member

a regression test would be welcome, if minimized — I wouldn't suggest just dumping OP's full code into a test case

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

5 participants