Skip to content

Fix #859 #1062

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

Merged
merged 3 commits into from
Feb 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
}
compareWild
case tp2: LazyRef =>
isSubType(tp1, tp2.ref)
!tp2.evaluating && isSubType(tp1, tp2.ref)
case tp2: AnnotatedType =>
isSubType(tp1, tp2.tpe) // todo: refine?
case tp2: ThisType =>
Expand Down Expand Up @@ -299,7 +299,10 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
}
compareWild
case tp1: LazyRef =>
isSubType(tp1.ref, tp2)
// If `tp1` is in train of being evaluated, don't force it
// because that would cause an assertionError. Return false instead.
// See i859.scala for an example where we hit this case.
!tp1.evaluating && isSubType(tp1.ref, tp2)
case tp1: AnnotatedType =>
isSubType(tp1.tpe, tp2)
case AndType(tp11, tp12) =>
Expand Down
3 changes: 2 additions & 1 deletion src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1972,14 +1972,15 @@ object Types {
case class LazyRef(refFn: () => Type) extends UncachedProxyType with ValueType {
private var myRef: Type = null
private var computed = false
lazy val ref = {
def ref = {
if (computed) assert(myRef != null)
else {
computed = true
myRef = refFn()
}
myRef
}
def evaluating = computed && myRef == null
override def underlying(implicit ctx: Context) = ref
override def toString = s"LazyRef($ref)"
override def equals(other: Any) = other match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,12 @@ object Scala2Unpickler {
case cinfo => (Nil, cinfo)
}
val ost =
if ((selfInfo eq NoType) && (denot is ModuleClass))
if ((selfInfo eq NoType) && (denot is ModuleClass) && denot.sourceModule.exists)
// it seems sometimes the source module does not exist for a module class.
// An example is `scala.reflect.internal.Trees.Template$. Without the
// `denot.sourceModule.exists` provision i859.scala crashes in the backend.
denot.owner.thisType select denot.sourceModule
else selfInfo

denot.info = ClassInfo(denot.owner.thisType, denot.classSymbol, Nil, decls, ost) // first rough info to avoid CyclicReferences
var parentRefs = ctx.normalizeToClassRefs(parents, cls, decls)
if (parentRefs.isEmpty) parentRefs = defn.ObjectType :: Nil
Expand Down
1 change: 1 addition & 0 deletions test/dotc/tests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class tests extends CompilerTest {

@Test def pos_i871 = compileFile(posSpecialDir, "i871", scala2mode)
@Test def pos_variancesConstr = compileFile(posSpecialDir, "variances-constr", scala2mode)
@Test def pos_859 = compileFile(posSpecialDir, "i859", scala2mode)(allowDeepSubtypes)

@Test def new_all = compileFiles(newDir, twice)

Expand Down
3 changes: 3 additions & 0 deletions tests/pos-special/i859.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Analyzer {
def foo: scala.tools.nsc.Global = ???
}