Skip to content

Commit b0d3861

Browse files
authored
Merge pull request #2827 from dotty-staging/topic/goto-2.12
Make dotty compile with 2.12.3
2 parents 91d3ec1 + 97ed06e commit b0d3861

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+243
-583
lines changed

compiler/src/dotty/tools/dotc/config/CompilerCommand.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Settings._
66
import core.Contexts._
77
import util.DotClass
88
import Properties._
9+
import scala.collection.JavaConverters._
910

1011
object CompilerCommand extends DotClass {
1112

@@ -43,10 +44,9 @@ object CompilerCommand extends DotClass {
4344
if (!Files.exists(path))
4445
throw new java.io.FileNotFoundException("argument file %s could not be found" format path.getFileName)
4546

46-
import scala.collection.JavaConversions._
4747
val lines = Files.readAllLines(path) // default to UTF-8 encoding
4848

49-
val params = lines map stripComment mkString " "
49+
val params = lines.asScala map stripComment mkString " "
5050
CommandLineParser.tokenize(params)
5151
}
5252

compiler/src/dotty/tools/dotc/core/StdNames.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,12 +325,15 @@ object StdNames {
325325
val ArrayAnnotArg: N = "ArrayAnnotArg"
326326
val Constant: N = "Constant"
327327
val ConstantType: N = "ConstantType"
328+
val doubleHash: N = "doubleHash"
328329
val ExistentialTypeTree: N = "ExistentialTypeTree"
329330
val Flag : N = "Flag"
331+
val floatHash: N = "floatHash"
330332
val Ident: N = "Ident"
331333
val Import: N = "Import"
332334
val Literal: N = "Literal"
333335
val LiteralAnnotArg: N = "LiteralAnnotArg"
336+
val longHash: N = "longHash"
334337
val Modifiers: N = "Modifiers"
335338
val NestedAnnotArg: N = "NestedAnnotArg"
336339
val NoFlags: N = "NoFlags"
@@ -353,6 +356,7 @@ object StdNames {
353356
val UNIT : N = "UNIT"
354357
val add_ : N = "add"
355358
val annotation: N = "annotation"
359+
val anyHash: N = "anyHash"
356360
val anyValClass: N = "anyValClass"
357361
val append: N = "append"
358362
val apply: N = "apply"

compiler/src/dotty/tools/dotc/parsing/MarkupParsers.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ object MarkupParsers {
8585

8686
var xEmbeddedBlock = false
8787

88-
private var debugLastStartElement = new mutable.Stack[(Int, String)]
89-
private def debugLastPos = debugLastStartElement.top._1
90-
private def debugLastElem = debugLastStartElement.top._2
88+
private var debugLastStartElement = List.empty[(Int, String)]
89+
private def debugLastPos = debugLastStartElement.head._1
90+
private def debugLastElem = debugLastStartElement.head._2
9191

9292
private def errorBraces() = {
9393
reportSyntaxError("in XML content, please use '}}' to express '}'")
@@ -280,10 +280,10 @@ object MarkupParsers {
280280
if (qname == "xml:unparsed")
281281
return xUnparsed
282282

283-
debugLastStartElement.push((start, qname))
283+
debugLastStartElement = (start, qname) :: debugLastStartElement
284284
val ts = content
285285
xEndTag(qname)
286-
debugLastStartElement.pop()
286+
debugLastStartElement = debugLastStartElement.tail
287287
val pos = Position(start, curOffset, start)
288288
qname match {
289289
case "xml:group" => handle.group(pos, ts)
@@ -417,7 +417,7 @@ object MarkupParsers {
417417
def xPattern: Tree = {
418418
var start = curOffset
419419
val qname = xName
420-
debugLastStartElement.push((start, qname))
420+
debugLastStartElement = (start, qname) :: debugLastStartElement
421421
xSpaceOpt()
422422

423423
val ts = new ArrayBuffer[Tree]
@@ -457,7 +457,7 @@ object MarkupParsers {
457457

458458
while (doPattern) { } // call until false
459459
xEndTag(qname)
460-
debugLastStartElement.pop()
460+
debugLastStartElement = debugLastStartElement.tail
461461
}
462462

463463
handle.makeXMLpat(Position(start, curOffset, start), qname, ts)

compiler/src/dotty/tools/dotc/transform/InterceptedMethods.scala

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import dotty.tools.dotc.ast.Trees._
2121
import dotty.tools.dotc.ast.{untpd, tpd}
2222
import dotty.tools.dotc.core.Constants.Constant
2323
import dotty.tools.dotc.core.Types.MethodType
24-
import dotty.tools.dotc.core.Names.Name
24+
import dotty.tools.dotc.core.Names.{ Name, TermName }
2525
import scala.collection.mutable.ListBuffer
2626
import dotty.tools.dotc.core.Denotations.SingleDenotation
2727
import dotty.tools.dotc.core.SymDenotations.SymDenotation
@@ -64,30 +64,18 @@ class InterceptedMethods extends MiniPhaseTransform {
6464
else tree
6565
}
6666

67+
// TODO: add missing cases from scalac
6768
private def poundPoundValue(tree: Tree)(implicit ctx: Context) = {
6869
val s = tree.tpe.widen.typeSymbol
69-
if (s == defn.NullClass) Literal(Constant(0))
70-
else {
71-
// Since we are past typer, we need to avoid creating trees carrying
72-
// overloaded types. This logic is custom (and technically incomplete,
73-
// although serviceable) for def hash. What is really needed is for
74-
// the overloading logic presently hidden away in a few different
75-
// places to be properly exposed so we can just call "resolveOverload"
76-
// after typer. Until then:
77-
78-
def alts = defn.ScalaRuntimeModule.info.member(nme.hash_)
79-
80-
// if tpe is a primitive value type, alt1 will match on the exact value,
81-
// taking in account that null.asInstanceOf[Int] == 0
82-
def alt1 = alts.suchThat(_.info.firstParamTypes.head =:= tree.tpe.widen)
8370

84-
// otherwise alt2 will match. alt2 also knows how to handle 'null' runtime value
85-
def alt2 = defn.ScalaRuntimeModule.info.member(nme.hash_)
86-
.suchThat(_.info.firstParamTypes.head.typeSymbol == defn.AnyClass)
71+
def staticsCall(methodName: TermName): Tree =
72+
ref(defn.staticsMethodRef(methodName)).appliedTo(tree)
8773

88-
Ident((if (s.isNumericValueClass) alt1 else alt2).termRef)
89-
.appliedTo(tree)
90-
}
74+
if (s == defn.NullClass) Literal(Constant(0))
75+
else if (s == defn.DoubleClass) staticsCall(nme.doubleHash)
76+
else if (s == defn.LongClass) staticsCall(nme.longHash)
77+
else if (s == defn.FloatClass) staticsCall(nme.floatHash)
78+
else staticsCall(nme.anyHash)
9179
}
9280

9381
override def transformApply(tree: Apply)(implicit ctx: Context, info: TransformerInfo): Tree = {

compiler/src/dotty/tools/dotc/transform/LinkScala2Impls.scala

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,18 @@ class LinkScala2Impls extends MiniPhase with IdentityDenotTransformer { thisTran
5050

5151
/** Copy definitions from implementation class to trait itself */
5252
private def augmentScala_2_12_Trait(mixin: ClassSymbol)(implicit ctx: Context): Unit = {
53+
def info_2_12(sym: Symbol) = sym.info match {
54+
case mt @ MethodType(paramNames @ nme.SELF :: _) =>
55+
// 2.12 seems to always assume the enclsing mixin class as self type parameter,
56+
// whereas 2.11 used the self type of this class instead.
57+
val selfType :: otherParamTypes = mt.paramInfos
58+
MethodType(paramNames, mixin.typeRef :: otherParamTypes, mt.resType)
59+
case info => info
60+
}
5361
def newImpl(sym: TermSymbol): Symbol = sym.copy(
5462
owner = mixin,
55-
name = if (sym.isConstructor) sym.name else ImplMethName(sym.name)
63+
name = if (sym.isConstructor) sym.name else ImplMethName(sym.name),
64+
info = info_2_12(sym)
5665
)
5766
for (sym <- mixin.implClass.info.decls)
5867
newImpl(sym.asTerm).enteredAfter(thisTransform)

compiler/src/dotty/tools/dotc/typer/VarianceChecker.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,10 @@ class VarianceChecker()(implicit ctx: Context) {
112112
case Some(VarianceError(tvar, required)) =>
113113
def msg = i"${varianceString(tvar.flags)} $tvar occurs in ${varianceString(required)} position in type ${sym.info} of $sym"
114114
if (ctx.scala2Mode && sym.owner.isConstructor) {
115-
ctx.migrationWarning(s"According to new variance rules, this is no longer accepted; need to annotate with @uncheckedVariance:\n$msg", sym.pos)
115+
ctx.migrationWarning(s"According to new variance rules, this is no longer accepted; need to annotate with @uncheckedVariance:\n$msg", pos)
116116
patch(Position(pos.end), " @scala.annotation.unchecked.uncheckedVariance") // TODO use an import or shorten if possible
117117
}
118-
else ctx.error(msg, sym.pos)
118+
else ctx.error(msg, pos)
119119
case None =>
120120
}
121121

compiler/test/dotc/scala-collections.blacklist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
scala/runtime/ScalaRunTime.scala
2+
# Doesn't compile since we're not on 2.11 anymore
3+
14
## Errors having to do with bootstrap
25

36
scala/Function1.scala

compiler/test/dotc/tests.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ class tests extends CompilerTest {
224224
|../scala2-library/src/library/scala/package.scala
225225
|../scala2-library/src/library/scala/collection/GenSeqLike.scala
226226
|../scala2-library/src/library/scala/collection/SeqLike.scala
227-
|../scala2-library/src/library/scala/collection/generic/GenSeqFactory.scala""".stripMargin)
227+
|../scala2-library/src/library/scala/collection/generic/GenSeqFactory.scala""".stripMargin)(scala2mode ++ defaultOptions)
228228
@Test def compileIndexedSeq = compileLine("../scala2-library/src/library/scala/collection/immutable/IndexedSeq.scala")
229229
@Test def compileParSetLike = compileLine("../scala2-library/src/library/scala/collection/parallel/mutable/ParSetLike.scala")
230230
@Test def compileParSetSubset = compileLine(

compiler/test/dotty/tools/ShowClassTests.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,14 @@ class ShowClassTests extends DottyTest {
6464
if (blackList contains path)
6565
debug_println(s"blacklisted package: $path")
6666
else {
67-
for (
68-
sym <- pkg.info.decls if sym.owner == pkg.moduleClass && !(sym.name.toString contains '$')
69-
) {
70-
debug_println(s"showing $sym in ${pkg.fullName}")
71-
if (sym is PackageVal) showPackage(sym.asTerm)
72-
else if (sym.isClass && !(sym is Module)) showClass(sym)
73-
else if (sym is ModuleVal) showClass(sym.moduleClass)
74-
}
67+
pkg.info.decls
68+
.filter(sym => sym.owner == pkg.moduleClass && !(sym.name.toString contains '$'))
69+
.foreach { sym =>
70+
debug_println(s"showing $sym in ${pkg.fullName}")
71+
if (sym is PackageVal) showPackage(sym.asTerm)
72+
else if (sym.isClass && !(sym is Module)) showClass(sym)
73+
else if (sym is ModuleVal) showClass(sym.moduleClass)
74+
}
7575
}
7676
}
7777

compiler/test/dotty/tools/dotc/CompilationTests.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class CompilationTests extends ParallelTesting {
5757
"../scala2-library/src/library/scala/collection/SeqLike.scala",
5858
"../scala2-library/src/library/scala/collection/generic/GenSeqFactory.scala"
5959
),
60-
defaultOptions
60+
scala2Mode
6161
) +
6262
compileFilesInDir("../tests/pos-special/spec-t5545", defaultOptions) +
6363
compileFilesInDir("../tests/pos-special/strawman-collections", defaultOptions) +

0 commit comments

Comments
 (0)