Skip to content

regression: assertion error in Mixin.transformInfo, with $$anon script wrapper #4202

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
scabug opened this issue Jan 29, 2011 · 18 comments
Closed
Assignees

Comments

@scabug
Copy link

scabug commented Jan 29, 2011

=== What steps will reproduce the problem ===

def x[N[_]] = ()

trait ExistT[M[_]] {
  x[M]
}

=== What is the expected behavior? ===

Compiles okay, as per 2.8.1

=== What do you see instead? ===

java.lang.AssertionError: assertion failed
	at scala.Predef$$.assert(Predef.scala:85)
	at scala.tools.nsc.transform.Mixin.transformInfo(Mixin.scala:375)
	at scala.tools.nsc.transform.InfoTransform$$Phase$$$$anon$$1.transform(InfoTransform.scala:38)
	at scala.tools.nsc.symtab.Symbols$$Symbol.rawInfo(Symbols.scala:774)
	at scala.tools.nsc.symtab.Symbols$$Symbol.info(Symbols.scala:717)
	at scala.tools.nsc.transform.Mixin$$MixinTransformer.scala$$tools$$nsc$$transform$$Mixin$$MixinTransformer$$$$postTransform(Mixin.scala:1113)
	at scala.tools.nsc.transform.Mixin$$MixinTransformer$$$$anonfun$$23.apply(Mixin.scala:1213)
	at scala.tools.nsc.transform.Mixin$$MixinTransformer$$$$anonfun$$23.apply(Mixin.scala:1213)
	at scala.tools.nsc.symtab.SymbolTable.atPhase(SymbolTable.scala:96)
	at scala.tools.nsc.transform.Mixin$$MixinTransformer.transform(Mixin.scala:1213)
	at scala.tools.nsc.ast.Trees$$Transformer.transformTemplate(Trees.scala:860)
	at scala.tools.nsc.ast.Trees$$Transformer$$$$anonfun$$transform$$2.apply(Trees.scala:752)
	at scala.tools.nsc.ast.Trees$$Transformer$$$$anonfun$$transform$$2.apply(Trees.scala:751)
	at scala.tools.nsc.ast.Trees$$Transformer.atOwner(Trees.scala:884)
	at scala.tools.nsc.ast.Trees$$Transformer.transform(Trees.scala:750)
	at scala.tools.nsc.transform.Mixin$$MixinTransformer.transform(Mixin.scala:1212)
	at scala.tools.nsc.ast.Trees$$Transformer$$$$anonfun$$transformStats$$1.apply(Trees.scala:876)
	at scala.tools.nsc.ast.Trees$$Transformer$$$$anonfun$$transformStats$$1.apply(Trees.scala:874)
	at scala.collection.immutable.List.loop$$1(List.scala:117)
	at scala.collection.immutable.List.mapConserve(List.scala:133)
	at scala.tools.nsc.ast.Trees$$Transformer.transformStats(Trees.scala:874)
	at scala.tools.nsc.ast.Trees$$Transformer$$$$anonfun$$transform$$1.apply(Trees.scala:746)
	at scala.tools.nsc.ast.Trees$$Transformer$$$$anonfun$$transform$$1.apply(Trees.scala:746)
	at scala.tools.nsc.ast.Trees$$Transformer.atOwner(Trees.scala:884)
	at scala.tools.nsc.ast.Trees$$Transformer.transform(Trees.scala:745)
	at scala.tools.nsc.transform.Mixin$$MixinTransformer.transform(Mixin.scala:1212)
	at scala.tools.nsc.ast.Trees$$Transformer.transformUnit(Trees.scala:877)
	at scala.tools.nsc.transform.Transform$$Phase.apply(Transform.scala:30)

=== Additional information ===

No crash after s/trait/class/.

I was actually trying to reproduce the following spurious compile error from the scalaz branch for Scala 2.9.x, from this tree: https://github.com/scalaz/scalaz/tree/3a58739500416eeda09d5150a2f3f7d1db2ad86e

I plan to isolate it further and lodge a separate ticket.

[error] /home/scalatools/hudson/.hudson/jobs/scalaz/workspace/http/src/main/scala/scalaz/http/response/Response.scala:50: kinds of the type arguments (OUT) do not conform to the expected kinds of the type parameters (type OUT).
[error] OUT's type parameters do not match type OUT's expected parameters: <none>'s bounds <notype> are stricter than type _'s declared bounds >: Nothing <: Any
[error]   def apply(l: StatusLine) = response[OUT](l, headers, body)
[error]                                      ^
[error] /home/scalatools/hudson/.hudson/jobs/scalaz/workspace/http/src/main/scala/scalaz/http/request/Request.scala:36: kinds of the type arguments (IN) do not conform to the expected kinds of the type parameters (type IN).
[error] IN's type parameters do not match type IN's expected parameters: <none>'s bounds <notype> are stricter than type _'s declared bounds >: Nothing <: Any
[error]   def apply(h: RequestHeader, v: NonEmptyList[Char]) = request[IN](line, (h, v) :: headers, body)

=== What versions of the following are you using? ===

  • Scala: 2.9.0.r24073-b20110124174250
@scabug
Copy link
Author

scabug commented Jan 29, 2011

Imported From: https://issues.scala-lang.org/browse/SI-4202?orig=1
Reporter: @retronym

@scabug
Copy link
Author

scabug commented Jan 29, 2011

@paulp said:
Oddly this compiles (and runs) fine for me with versions of scala both before and after yours. Are you giving it a command line option or something?

Welcome to Scala version 2.9.0.r24136-b20110128174513 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_22).

scala> object o {
     |   def x[N[_]] = ()
     | 
     |   trait ExistT[M[_]] {
     |     x[M]
     |   }
     | }
defined module o

scala> o.x

Welcome to Scala version 2.9.0.r24068-b20110123233401 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_22).

scala> object o {
     |   def x[N[_]] = ()
     | 
     |   trait ExistT[M[_]] {
     |     x[M]
     |   }
     | }
defined module o

scala> o.x

@scabug
Copy link
Author

scabug commented Jan 30, 2011

@retronym said:
Oh darn. I was running it as a script. Working that back to something I can demonstrate in vanilla scalac:

object Main {
  def x[N[_]] = ()

  def main = {
    class $$anon { // rename to 'anon' to get rid of crash
      object scratch {

        trait ExistT[M[_]] { // s/trait/class/ to get rid of crash
          x[M]
        }
      }
    }
  }
}

Gives:

 ~/code/scratch: scalac -version
Scala compiler version 2.8.1.final -- Copyright 2002-2010, LAMP/EPFL
 ~/code/scratch: scalac /Users/jason/code/scalaz/core/scratch.scala ~/code/scratch: ~/usr/scala-2.9.0.r24145-b20110130020134/bin/scalac   /Users/jason/code/scalaz/core/scratch.scala
Exception in thread "main" java.lang.AssertionError: assertion failed
	at scala.Predef$$.assert(Predef.scala:85)
	at scala.tools.nsc.transform.Mixin.transformInfo(Mixin.scala:375)

@scabug
Copy link
Author

scabug commented Feb 1, 2011

@adriaanm said:

object Main {
  def x = 1
  class $$anon { // rename to 'anon' to get rid of crash
    object scratch {
      trait ExistT { // s/trait/class/ to get rid of crash
        x
      }
    }
  }
}

look ma, no type constructors!

@scabug
Copy link
Author

scabug commented Feb 1, 2011

@retronym said:
Looks like I need to work on my minimization skills. 'tcpoly' tag duly removed.

For the record, my use of '$$' was just to replicate the inner machinations of the script runner. The following crashes, when run as a script.

script.scala: def x{};trait X{x}

@scabug
Copy link
Author

scabug commented Feb 5, 2011

@retronym said:
Here's another example, distilled from Specs:

object t4202 {
  () => {
    trait T {
      def t = ()
    }
    object T2 extends T {
      t
    }
  }
}

@scabug
Copy link
Author

scabug commented Feb 5, 2011

@paulp said:
Replying to [comment:7 retronym]:

Here's another example, distilled from Specs:

That looks an awful lot like #2897, which is:

 def f1(t: String) = {
    trait T {
      def xs = Nil map (_ => t)
    }
    ()
  }

Not exactly the same bug I don't think, just brothers.

@scabug
Copy link
Author

scabug commented Feb 6, 2011

@paulp said:
Actually they are the same bug I think. By the way "object T2" in your comment doesn't have any bearing on the bug, it crashes fine without it.

Putting r24206 to work, here it is after lazyvals:

// I'm using: () => { trait T { def t = () } }
  object t4202 final
      constructor t4202 
      value <local t4202> 
          anonymous class $$anonfun final <synthetic>
              constructor $$anonfun 
              method apply final
              method apply final <bridge>
              value <local $$anonfun> 

And then here after lambdalift. Notice the trait implementation class is being renamed to "T$$class$$1" which is pretty clearly wrong. I'm able to push the error downfield by excluding .isImplClass but the problem is deeper.

  object t4202 final
      anonymous class $$anonfun$$1 final <synthetic>
          constructor $$anonfun$$1 
          method apply final
          method apply final <bridge>
*         trait T$$1 abstract
*             method t 
*             value <local T> 
*             value t4202$$$$anonfun$$T$$$$$$outer <synthetic> <stable>
*         trait T$$class$$1 abstract
*             method $$init$$ 
*             method t 
*             value <local T$$class> 
          value <local $$anonfun> 

@scabug
Copy link
Author

scabug commented Feb 6, 2011

@paulp said:
Well, I thought it was clearly wrong based on the fact that 1406/1406 implementation classes in trunk have a name ending in "$$class". But 2.8.1 does compile it with that name, so maybe it's not wrong.

-rw-r--r--  1 paulp  staff    309 Feb  6 01:08 t4202$$$$anonfun$$1$$T$$1.class
-rw-r--r--  1 paulp  staff    442 Feb  6 01:08 t4202$$$$anonfun$$1$$T$$class$$1.class
-rw-r--r--  1 paulp  staff    754 Feb  6 01:08 t4202$$$$anonfun$$1.class
-rw-r--r--  1 paulp  staff    407 Feb  6 01:08 t4202$$.class
-rw-r--r--  1 paulp  staff    435 Feb  6 01:08 t4202.class

Drives me nuts trying to infer everything from the implementation. Is this documented somewhere?

@scabug
Copy link
Author

scabug commented Feb 8, 2011

@adriaanm said:
as I understand it, the fix for this is simple: don't give interpreter wrappers blingy names (might I suggest replacing $$ by CHF?)

we don't officially deal in dollars anyway (at least not in user-supplied names)

Paul, I'm sorry I can't provide more insight on the use of the dollar in generated names, but I think we can settle for a pragmatic solution here. Could the deeper problem simply be that calling this class $$anon triggers a conversion that's not meant to be done in here?

    val ANON_CLASS_NAME: NameType    = "$$anon"
[...]
    final def isAnonymousClass    = isClass && (name containsName tpnme.ANON_CLASS_NAME)

@scabug
Copy link
Author

scabug commented Feb 8, 2011

@retronym said:
As described in the comments above, the same assertion trips with the following, but maybe that's a different bug.

object t4202 {
  () => {
    trait T {
      def t = ()
    } 
  }
}

@scabug
Copy link
Author

scabug commented Feb 14, 2011

@adriaanm said:
Hubert, wild guess: could this be related to r24225?

In any case, it does not seem to be a REPL issue, based on Jason's latest comment.

@scabug
Copy link
Author

scabug commented Feb 14, 2011

@hubertp said:
Well it is definitely not caused by it, given that my commit is from 6 days ago but I will try to have a look at it.

@scabug
Copy link
Author

scabug commented Feb 22, 2011

@hubertp said:
(In r24326) Closes #4202 and removes empty TreeHashMap (superseded by HashMap implementation). No review

@scabug
Copy link
Author

scabug commented Mar 12, 2011

@paulp said:
This still crashes as of r24432.

object t4202 {
  () => {
    trait T {
      def t = ()
    }
    object T2 extends T {
      t
    }
  }
}

@scabug
Copy link
Author

scabug commented Mar 21, 2011

@hubertp said:
(In r24527) Closes #4202 again, closes #4363. if someone can enlighten me why we actually had that exclusion for companion objects in the first place I would be grateful. review by odersky

@scabug
Copy link
Author

scabug commented Mar 21, 2011

@paulp said:
Replying to [comment:21 plocinic]:

(In r24527) Closes #4202 again, closes #4363. if someone can enlighten me why we actually had that exclusion for companion objects in the first place I would be grateful.

r8575
"fixed gilles problem with spurious recursive types"

For whatever you may be able to make of that.

@scabug
Copy link
Author

scabug commented Mar 21, 2011

@hubertp said:
Replying to [comment:22 extempore]:

r8575
"fixed gilles problem with spurious recursive types"

For whatever you may be able to make of that.

Yeah, I used my svn skills to find that too, though the actual comment isn't very informative. Also I assumed that it might be no longer valid given that it was 6 years ago ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants