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) +

compiler/test/dotty/tools/vulpix/SummaryReport.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ final class NoSummaryReport extends SummaryReporting {
5959
* which outputs to a log file in `./testlogs/`
6060
*/
6161
final class SummaryReport extends SummaryReporting {
62-
import scala.collection.JavaConversions._
62+
import scala.collection.JavaConverters._
6363

6464
private val startingMessages = new java.util.concurrent.ConcurrentLinkedDeque[String]
6565
private val failedTests = new java.util.concurrent.ConcurrentLinkedDeque[String]
@@ -102,9 +102,9 @@ final class SummaryReport extends SummaryReporting {
102102
|""".stripMargin
103103
)
104104

105-
startingMessages.foreach(rep.append)
105+
startingMessages.asScala.foreach(rep.append)
106106

107-
failedTests.map(x => s" $x\n").foreach(rep.append)
107+
failedTests.asScala.map(x => s" $x\n").foreach(rep.append)
108108

109109
// If we're compiling locally, we don't need instructions on how to
110110
// reproduce failures
@@ -121,15 +121,15 @@ final class SummaryReport extends SummaryReporting {
121121

122122
rep += '\n'
123123

124-
reproduceInstructions.foreach(rep.append)
124+
reproduceInstructions.asScala.foreach(rep.append)
125125

126126
// If we're on the CI, we want everything
127127
if (!isInteractive) println(rep.toString)
128128

129129
TestReporter.logPrintln(rep.toString)
130130

131131
// Perform cleanup callback:
132-
if (cleanUps.nonEmpty) cleanUps.foreach(_.apply())
132+
if (!cleanUps.isEmpty()) cleanUps.asScala.foreach(_.apply())
133133
}
134134

135135
private def removeColors(msg: String): String =

library/src/dotty/runtime/LazyVals.scala

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,19 @@ import scala.annotation.tailrec
66
* Helper methods used in thread-safe lazy vals.
77
*/
88
object LazyVals {
9-
private val unsafe = scala.concurrent.util.Unsafe.instance
9+
private val unsafe: sun.misc.Unsafe =
10+
classOf[sun.misc.Unsafe].getDeclaredFields.find { field =>
11+
field.getType == classOf[sun.misc.Unsafe] && {
12+
field.setAccessible(true)
13+
true
14+
}
15+
}
16+
.map(_.get(null).asInstanceOf[sun.misc.Unsafe])
17+
.getOrElse {
18+
throw new ExceptionInInitializerError {
19+
new IllegalStateException("Can't find instance of sun.misc.Unsafe")
20+
}
21+
}
1022

1123
final val BITS_PER_LAZY_VAL = 2L
1224
final val LAZY_VAL_MASK = 3L
@@ -22,7 +34,7 @@ object LazyVals {
2234
if (debug)
2335
println(s"CAS($t, $offset, $e, $v, $ord)")
2436
val mask = ~(LAZY_VAL_MASK << ord * BITS_PER_LAZY_VAL)
25-
val n = (e & mask) | (v << (ord * BITS_PER_LAZY_VAL))
37+
val n = (e & mask) | (v.toLong << (ord * BITS_PER_LAZY_VAL))
2638
compareAndSet(t, offset, e, n)
2739
}
2840
@inline def setFlag(t: Object, offset: Long, v: Int, ord: Int) = {

library/src/scala/compat/java8/JFunction1.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,12 @@ public interface JFunction1<T1, R> extends scala.Function1<T1, R> {
1313
@Override
1414
@SuppressWarnings("unchecked")
1515
default <A> scala.Function1<T1, A> andThen(scala.Function1<R, A> g) {
16-
return scala.Function1$class.andThen(this, g);
16+
return x -> g.apply(this.apply(x));
1717
}
18-
1918
@Override
2019
@SuppressWarnings("unchecked")
2120
default <A> scala.Function1<A, R> compose(scala.Function1<A, T1> g) {
22-
return scala.Function1$class.compose(this, g);
21+
return x -> this.apply(g.apply(x));
2322
}
2423
@SuppressWarnings("unchecked")
2524
default void apply$mcVI$sp(int v1) {

library/src/scala/compat/java8/JFunction10.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ public interface JFunction10<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, R> extends
1212

1313
@SuppressWarnings("unchecked")
1414
default scala.Function1<T1, scala.Function1<T2, scala.Function1<T3, scala.Function1<T4, scala.Function1<T5, scala.Function1<T6, scala.Function1<T7, scala.Function1<T8, scala.Function1<T9, scala.Function1<T10, R>>>>>>>>>> curried() {
15-
return scala.Function10$class.curried(this);
15+
throw new UnsupportedOperationException("todo");
1616
}
1717

1818
@SuppressWarnings("unchecked")
1919
default scala.Function1<scala.Tuple10<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>, R> tupled() {
20-
return scala.Function10$class.tupled(this);
20+
throw new UnsupportedOperationException("todo");
2121
}
2222

2323

library/src/scala/compat/java8/JFunction11.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ public interface JFunction11<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, R> ex
1212

1313
@SuppressWarnings("unchecked")
1414
default scala.Function1<T1, scala.Function1<T2, scala.Function1<T3, scala.Function1<T4, scala.Function1<T5, scala.Function1<T6, scala.Function1<T7, scala.Function1<T8, scala.Function1<T9, scala.Function1<T10, scala.Function1<T11, R>>>>>>>>>>> curried() {
15-
return scala.Function11$class.curried(this);
15+
throw new UnsupportedOperationException("todo");
1616
}
1717

1818
@SuppressWarnings("unchecked")
1919
default scala.Function1<scala.Tuple11<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>, R> tupled() {
20-
return scala.Function11$class.tupled(this);
20+
throw new UnsupportedOperationException("todo");
2121
}
2222

2323

library/src/scala/compat/java8/JFunction12.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ public interface JFunction12<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
1212

1313
@SuppressWarnings("unchecked")
1414
default scala.Function1<T1, scala.Function1<T2, scala.Function1<T3, scala.Function1<T4, scala.Function1<T5, scala.Function1<T6, scala.Function1<T7, scala.Function1<T8, scala.Function1<T9, scala.Function1<T10, scala.Function1<T11, scala.Function1<T12, R>>>>>>>>>>>> curried() {
15-
return scala.Function12$class.curried(this);
15+
throw new UnsupportedOperationException("todo");
1616
}
1717

1818
@SuppressWarnings("unchecked")
1919
default scala.Function1<scala.Tuple12<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>, R> tupled() {
20-
return scala.Function12$class.tupled(this);
20+
throw new UnsupportedOperationException("todo");
2121
}
2222

2323

library/src/scala/compat/java8/JFunction13.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ public interface JFunction13<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
1212

1313
@SuppressWarnings("unchecked")
1414
default scala.Function1<T1, scala.Function1<T2, scala.Function1<T3, scala.Function1<T4, scala.Function1<T5, scala.Function1<T6, scala.Function1<T7, scala.Function1<T8, scala.Function1<T9, scala.Function1<T10, scala.Function1<T11, scala.Function1<T12, scala.Function1<T13, R>>>>>>>>>>>>> curried() {
15-
return scala.Function13$class.curried(this);
15+
throw new UnsupportedOperationException("todo");
1616
}
1717

1818
@SuppressWarnings("unchecked")
1919
default scala.Function1<scala.Tuple13<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>, R> tupled() {
20-
return scala.Function13$class.tupled(this);
20+
throw new UnsupportedOperationException("todo");
2121
}
2222

2323

library/src/scala/compat/java8/JFunction14.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ public interface JFunction14<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
1212

1313
@SuppressWarnings("unchecked")
1414
default scala.Function1<T1, scala.Function1<T2, scala.Function1<T3, scala.Function1<T4, scala.Function1<T5, scala.Function1<T6, scala.Function1<T7, scala.Function1<T8, scala.Function1<T9, scala.Function1<T10, scala.Function1<T11, scala.Function1<T12, scala.Function1<T13, scala.Function1<T14, R>>>>>>>>>>>>>> curried() {
15-
return scala.Function14$class.curried(this);
15+
throw new UnsupportedOperationException("todo");
1616
}
1717

1818
@SuppressWarnings("unchecked")
1919
default scala.Function1<scala.Tuple14<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>, R> tupled() {
20-
return scala.Function14$class.tupled(this);
20+
throw new UnsupportedOperationException("todo");
2121
}
2222

2323

library/src/scala/compat/java8/JFunction15.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ public interface JFunction15<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
1212

1313
@SuppressWarnings("unchecked")
1414
default scala.Function1<T1, scala.Function1<T2, scala.Function1<T3, scala.Function1<T4, scala.Function1<T5, scala.Function1<T6, scala.Function1<T7, scala.Function1<T8, scala.Function1<T9, scala.Function1<T10, scala.Function1<T11, scala.Function1<T12, scala.Function1<T13, scala.Function1<T14, scala.Function1<T15, R>>>>>>>>>>>>>>> curried() {
15-
return scala.Function15$class.curried(this);
15+
throw new UnsupportedOperationException("todo");
1616
}
1717

1818
@SuppressWarnings("unchecked")
1919
default scala.Function1<scala.Tuple15<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>, R> tupled() {
20-
return scala.Function15$class.tupled(this);
20+
throw new UnsupportedOperationException("todo");
2121
}
2222

2323

0 commit comments

Comments
 (0)