Skip to content

Fix issues to make new collections compile again #4162

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
Mar 22, 2018
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
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ object desugar {
.withPos(mdef.pos.startPos)
val ValDef(selfName, selfTpt, _) = impl.self
val selfMods = impl.self.mods
if (!selfTpt.isEmpty || selfName != nme.WILDCARD) ctx.error(ObjectMayNotHaveSelfType(mdef), impl.self.pos)
if (!selfTpt.isEmpty) ctx.error(ObjectMayNotHaveSelfType(mdef), impl.self.pos)
val clsSelf = ValDef(selfName, SingletonTypeTree(Ident(moduleName)), impl.self.rhs)
.withMods(selfMods)
.withPos(impl.self.pos orElse impl.pos.startPos)
Expand Down
33 changes: 22 additions & 11 deletions compiler/src/dotty/tools/dotc/core/Denotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -332,14 +332,20 @@ object Denotations {
}

/** Handle merge conflict by throwing a `MergeError` exception */
private def mergeConflict(tp1: Type, tp2: Type)(implicit ctx: Context): Type = {
private def mergeConflict(tp1: Type, tp2: Type, that: Denotation)(implicit ctx: Context): Type = {
def showSymbol(sym: Symbol): String = if (sym.exists) sym.showLocated else "[unknown]"
def showType(tp: Type) = tp match {
case ClassInfo(_, cls, _, _, _) => cls.showLocated
case bounds: TypeBounds => i"type bounds $bounds"
case _ => tp.show
}
if (true) throw new MergeError(s"cannot merge ${showType(tp1)} with ${showType(tp2)}", tp1, tp2)
else throw new Error(s"cannot merge ${showType(tp1)} with ${showType(tp2)}") // flip condition for debugging
val msg =
s"""cannot merge
| ${showSymbol(this.symbol)} of type ${showType(tp1)} and
| ${showSymbol(that.symbol)} of type ${showType(tp2)}
"""
if (true) throw new MergeError(msg, tp1, tp2)
else throw new Error(msg) // flip condition for debugging
}

/** Merge parameter names of lambda types. If names in corresponding positions match, keep them,
Expand Down Expand Up @@ -389,13 +395,13 @@ object Denotations {
tp2 match {
case tp2: TypeBounds => if (safeIntersection) tp1 safe_& tp2 else tp1 & tp2
case tp2: ClassInfo if tp1 contains tp2 => tp2
case _ => mergeConflict(tp1, tp2)
case _ => mergeConflict(tp1, tp2, that)
}
case tp1: ClassInfo =>
tp2 match {
case tp2: ClassInfo if tp1.cls eq tp2.cls => tp1.derivedClassInfo(tp1.prefix & tp2.prefix)
case tp2: TypeBounds if tp2 contains tp1 => tp1
case _ => mergeConflict(tp1, tp2)
case _ => mergeConflict(tp1, tp2, that)
}
case tp1: MethodOrPoly =>
tp2 match {
Expand All @@ -420,9 +426,9 @@ object Denotations {
tp1.derivedLambdaType(
mergeParamNames(tp1, tp2), tp1.paramInfos,
infoMeet(tp1.resultType, tp2.resultType.subst(tp2, tp1)))
else mergeConflict(tp1, tp2)
else mergeConflict(tp1, tp2, that)
case _ =>
mergeConflict(tp1, tp2)
mergeConflict(tp1, tp2, that)
}
case _ =>
tp1 & tp2
Expand Down Expand Up @@ -523,7 +529,12 @@ object Denotations {
try infoMeet(info1, info2)
catch {
case ex: MergeError =>
if (pre.widen.classSymbol.is(Scala2x) || ctx.scala2Mode)
// TODO: this picks one type over the other whereas it might be better
// to return a MultiDenotation instead. But doing so would affect lots of
// things, starting with the return type of this method.
if (preferSym(sym2, sym1)) info2
else if (preferSym(sym1, sym2)) info1
else if (pre.widen.classSymbol.is(Scala2x) || ctx.scala2Mode)
info1 // follow Scala2 linearization -
// compare with way merge is performed in SymDenotation#computeMembersNamed
else
Expand Down Expand Up @@ -560,13 +571,13 @@ object Denotations {
tp2 match {
case tp2: TypeBounds => tp1 | tp2
case tp2: ClassInfo if tp1 contains tp2 => tp1
case _ => mergeConflict(tp1, tp2)
case _ => mergeConflict(tp1, tp2, that)
}
case tp1: ClassInfo =>
tp2 match {
case tp2: ClassInfo if tp1.cls eq tp2.cls => tp1.derivedClassInfo(tp1.prefix | tp2.prefix)
case tp2: TypeBounds if tp2 contains tp1 => tp2
case _ => mergeConflict(tp1, tp2)
case _ => mergeConflict(tp1, tp2, that)
}
case tp1: MethodOrPoly =>
tp2 match {
Expand All @@ -577,7 +588,7 @@ object Denotations {
mergeParamNames(tp1, tp2), tp1.paramInfos,
tp1.resultType | tp2.resultType.subst(tp2, tp1))
case _ =>
mergeConflict(tp1, tp2)
mergeConflict(tp1, tp2, that)
}
case _ =>
tp1 | tp2
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/NameKinds.scala
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ object NameKinds {
def infoString: String
}

object SimpleNameKind extends NameKind(UTF8) {
object SimpleNameKind extends NameKind(UTF8) { self =>
type ThisInfo = Info
val info = new Info
def mkString(underlying: TermName, info: ThisInfo) = unsupported("mkString")
Expand Down
8 changes: 7 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,13 @@ class Namer { typer: Typer =>

val selfInfo =
if (self.isEmpty) NoType
else if (cls.is(Module)) cls.owner.thisType.select(sourceModule)
else if (cls.is(Module)) {
val moduleType = cls.owner.thisType select sourceModule
if (self.name == nme.WILDCARD) moduleType
else recordSym(
ctx.newSymbol(cls, self.name, self.mods.flags, moduleType, coord = self.pos),
self)
}
else createSymbol(self)

// pre-set info, so that parent types can refer to type params
Expand Down
3 changes: 3 additions & 0 deletions compiler/test/dotty/tools/dotc/FromTastyTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ class FromTastyTests extends ParallelTesting {
"spec-super.scala",
"spec-sparsearray-old.scala",
"collections_1.scala",

// Infinite compilation
"t3612.scala",
)
)
step1.checkCompile() // Compile all files to generate the class files with tasty
Expand Down
2 changes: 1 addition & 1 deletion scala2-library
4 changes: 0 additions & 4 deletions tests/neg/i831.scala

This file was deleted.

2 changes: 1 addition & 1 deletion tests/pickling/desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ object desugar {
def foo1(first: Int, second: Int = 2)(third: Int = 3) = first + second
def foo2(first: Int)(second: Int = 2)(third: Int = 3) = first + second

object caseClasses {
object caseClasses { self =>
trait List[+T] {
def head: T
def tail: List[T]
Expand Down
2 changes: 1 addition & 1 deletion tests/pos/desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ object desugar {
def foo1(first: Int, second: Int = 2)(third: Int = 3) = first + second
def foo2(first: Int)(second: Int = 2)(third: Int = 3) = first + second

object caseClasses {
object caseClasses { self =>
trait List[+T] {
def head: T
def tail: List[T]
Expand Down
4 changes: 4 additions & 0 deletions tests/pos/i831.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
object Test { self =>
def a = 5
self.a
}
6 changes: 6 additions & 0 deletions tests/pos/t3612.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
trait C

class Outer {
object O0 extends C {}
object O extends C { self => }
}