diff options
-rw-r--r-- | compiler/src/dotty/tools/dotc/core/Symbols.scala | 11 | ||||
-rw-r--r-- | compiler/src/dotty/tools/dotc/core/Types.scala | 2 | ||||
-rw-r--r-- | compiler/src/dotty/tools/dotc/transform/FirstTransform.scala | 9 | ||||
-rw-r--r-- | compiler/src/dotty/tools/dotc/transform/LazyVals.scala | 2 | ||||
-rw-r--r-- | compiler/src/dotty/tools/dotc/typer/RefChecks.scala | 12 | ||||
-rw-r--r-- | compiler/src/dotty/tools/dotc/typer/Typer.scala | 7 | ||||
-rw-r--r-- | compiler/test/dotc/tests.scala | 4 | ||||
-rw-r--r-- | sbt-bridge/src/xsbt/DelegatingReporter.scala | 36 | ||||
-rw-r--r-- | tests/neg/i1706.scala | 3 | ||||
-rw-r--r-- | tests/pos/i2071.scala | 7 | ||||
-rw-r--r-- | tests/run/i2077.check | 1 | ||||
-rw-r--r-- | tests/run/i2077.scala | 10 |
12 files changed, 79 insertions, 25 deletions
diff --git a/compiler/src/dotty/tools/dotc/core/Symbols.scala b/compiler/src/dotty/tools/dotc/core/Symbols.scala index c5e064478..9d1d6481d 100644 --- a/compiler/src/dotty/tools/dotc/core/Symbols.scala +++ b/compiler/src/dotty/tools/dotc/core/Symbols.scala @@ -496,12 +496,15 @@ object Symbols { final def sourceFile(implicit ctx: Context): AbstractFile = { val file = associatedFile if (file != null && !file.path.endsWith("class")) file - else denot.topLevelClass.getAnnotation(defn.SourceFileAnnot) match { - case Some(sourceAnnot) => sourceAnnot.argumentConstant(0) match { - case Some(Constant(path: String)) => AbstractFile.getFile(path) + else { + val topLevelCls = denot.topLevelClass(ctx.withPhaseNoLater(ctx.flattenPhase)) + topLevelCls.getAnnotation(defn.SourceFileAnnot) match { + case Some(sourceAnnot) => sourceAnnot.argumentConstant(0) match { + case Some(Constant(path: String)) => AbstractFile.getFile(path) + case none => null + } case none => null } - case none => null } } diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index 639f5d142..2e471215b 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -3328,6 +3328,8 @@ object Types { zeroParamClass(tp.underlying) case tp: TypeVar => zeroParamClass(tp.underlying) + case tp: HKApply => + zeroParamClass(tp.superType) case _ => NoType } diff --git a/compiler/src/dotty/tools/dotc/transform/FirstTransform.scala b/compiler/src/dotty/tools/dotc/transform/FirstTransform.scala index 597146514..9e71fda5d 100644 --- a/compiler/src/dotty/tools/dotc/transform/FirstTransform.scala +++ b/compiler/src/dotty/tools/dotc/transform/FirstTransform.scala @@ -31,6 +31,9 @@ import StdNames._ * - eliminates self tree in Template and self symbol in ClassInfo * - collapsess all type trees to trees of class TypeTree * - converts idempotent expressions with constant types + * - drops branches of ifs using the rules + * if (true) A else B --> A + * if (false) A else B --> B */ class FirstTransform extends MiniPhaseTransform with InfoTransformer with AnnotationTransformer { thisTransformer => import ast.tpd._ @@ -187,6 +190,12 @@ class FirstTransform extends MiniPhaseTransform with InfoTransformer with Annota override def transformBlock(tree: Block)(implicit ctx: Context, info: TransformerInfo) = constToLiteral(tree) + override def transformIf(tree: If)(implicit ctx: Context, info: TransformerInfo) = + tree.cond match { + case Literal(Constant(c: Boolean)) => if (c) tree.thenp else tree.elsep + case _ => tree + } + // invariants: all modules have companion objects // all types are TypeTrees // all this types are explicit diff --git a/compiler/src/dotty/tools/dotc/transform/LazyVals.scala b/compiler/src/dotty/tools/dotc/transform/LazyVals.scala index a6ac71286..2035fb04b 100644 --- a/compiler/src/dotty/tools/dotc/transform/LazyVals.scala +++ b/compiler/src/dotty/tools/dotc/transform/LazyVals.scala @@ -139,7 +139,7 @@ class LazyVals extends MiniPhaseTransform with IdentityDenotTransformer { val holderSymbol = ctx.newSymbol(x.symbol.owner, holderName, containerFlags, holderImpl.typeRef, coord = x.pos) val initSymbol = ctx.newSymbol(x.symbol.owner, initName, initFlags, MethodType(Nil, tpe), coord = x.pos) - val result = ref(holderSymbol).select(lazyNme.value) + val result = ref(holderSymbol).select(lazyNme.value).withPos(x.pos) val flag = ref(holderSymbol).select(lazyNme.initialized) val initer = valueInitter.changeOwnerAfter(x.symbol, initSymbol, this) val initBody = diff --git a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala index e8ff7d572..d61f5fa68 100644 --- a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala +++ b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala @@ -739,11 +739,7 @@ import RefChecks._ * * 2. It warns about references to symbols labeled deprecated or migration. - * 3. It performs the following transformations: - * - * - if (true) A else B --> A - * if (false) A else B --> B - * - macro definitions are eliminated. + * 3. It eliminates macro definitions. * * 4. It makes members not private where necessary. The following members * cannot be private in the Java model: @@ -836,12 +832,6 @@ class RefChecks extends MiniPhase { thisTransformer => tree } - override def transformIf(tree: If)(implicit ctx: Context, info: TransformerInfo) = - tree.cond.tpe match { - case ConstantType(value) => if (value.booleanValue) tree.thenp else tree.elsep - case _ => tree - } - override def transformNew(tree: New)(implicit ctx: Context, info: TransformerInfo) = { currentLevel.enterReference(tree.tpe.typeSymbol, tree.pos) tree diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index ccfe218b3..fd0c7c73d 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -1080,6 +1080,13 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit (if (isVarPattern(arg)) desugar.patternVar(arg) else arg, tparam.paramBounds) else (arg, WildcardType) + if (tpt1.symbol.isClass) + tparam match { + case tparam: Symbol => + // This is needed to get the test `compileParSetSubset` to work + tparam.ensureCompleted() + case _ => + } typed(desugaredArg, argPt) } args.zipWithConserve(tparams)(typedArg(_, _)).asInstanceOf[List[Tree]] diff --git a/compiler/test/dotc/tests.scala b/compiler/test/dotc/tests.scala index 78a8aefd5..01db2d9cc 100644 --- a/compiler/test/dotc/tests.scala +++ b/compiler/test/dotc/tests.scala @@ -225,6 +225,10 @@ class tests extends CompilerTest { |../scala-scala/src/library/scala/collection/generic/GenSeqFactory.scala""".stripMargin) @Test def compileIndexedSeq = compileLine("../scala-scala/src/library/scala/collection/immutable/IndexedSeq.scala") @Test def compileParSetLike = compileLine("../scala-scala/src/library/scala/collection/parallel/mutable/ParSetLike.scala") + @Test def compileParSetSubset = compileLine( + """../scala-scala/src/library/scala/collection/parallel/mutable/ParSetLike.scala + |../scala-scala/src/library/scala/collection/parallel/mutable/ParSet.scala + |../scala-scala/src/library/scala/collection/mutable/SetLike.scala""".stripMargin)(scala2mode ++ defaultOptions) @Test def dotty = { dottyBootedLib diff --git a/sbt-bridge/src/xsbt/DelegatingReporter.scala b/sbt-bridge/src/xsbt/DelegatingReporter.scala index e704a29c9..e637ddcf3 100644 --- a/sbt-bridge/src/xsbt/DelegatingReporter.scala +++ b/sbt-bridge/src/xsbt/DelegatingReporter.scala @@ -27,15 +27,23 @@ final class DelegatingReporter(delegate: xsbti.Reporter) extends Reporter case _ => xsbti.Severity.Info } - val position = new Position { - def line: Maybe[Integer] = Maybe.just(cont.pos.line) - def lineContent: String = cont.pos.lineContent - def offset: Maybe[Integer] = Maybe.just(cont.pos.point) - def pointer: Maybe[Integer] = Maybe.just(cont.pos.point) - def pointerSpace: Maybe[String] = Maybe.just(" " * cont.pos.point) - def sourceFile: Maybe[java.io.File] = maybe(Option(cont.pos.source.file.file)) - def sourcePath: Maybe[String] = maybe(Option(cont.pos.source.file.file).map(_.getPath)) - } + val position = + if (cont.pos.exists) { + val pos = cont.pos + val src = pos.source + new Position { + val sourceFile: Maybe[java.io.File] = maybe(Option(src.file.file)) + val sourcePath: Maybe[String] = maybe(Option(src.file.path)) + val line: Maybe[Integer] = Maybe.just(pos.line) + val lineContent: String = pos.lineContent.stripLineEnd + val offset: Maybe[Integer] = Maybe.just(pos.point) + val pointer: Maybe[Integer] = Maybe.just(pos.point - src.startOfLine(pos.point)) + val pointerSpace: Maybe[String] = Maybe.just( + ((lineContent: Seq[Char]).take(pointer.get).map { case '\t' => '\t'; case x => ' ' }).mkString + ) + } + } else + noPosition val sb = new StringBuilder() sb.append(messageAndPos(cont.contained, cont.pos, diagnosticLevel(cont))) @@ -50,4 +58,14 @@ final class DelegatingReporter(delegate: xsbti.Reporter) extends Reporter case None => Maybe.nothing[T] case Some(s) => Maybe.just[T](s) } + + private[this] val noPosition = new Position { + val line: Maybe[Integer] = Maybe.nothing[Integer] + val lineContent: String = "" + val offset: Maybe[Integer] = Maybe.nothing[Integer] + val pointer: Maybe[Integer] = Maybe.nothing[Integer] + val pointerSpace: Maybe[String] = Maybe.nothing[String] + val sourceFile: Maybe[java.io.File] = Maybe.nothing[java.io.File] + val sourcePath: Maybe[String] = Maybe.nothing[String] + } } diff --git a/tests/neg/i1706.scala b/tests/neg/i1706.scala new file mode 100644 index 000000000..b55ff6e2d --- /dev/null +++ b/tests/neg/i1706.scala @@ -0,0 +1,3 @@ +object Test { + println (Object.reflect.runtime.universe.reify (new Object().getClass)) // error: not found Object +} diff --git a/tests/pos/i2071.scala b/tests/pos/i2071.scala new file mode 100644 index 000000000..1855dccf4 --- /dev/null +++ b/tests/pos/i2071.scala @@ -0,0 +1,7 @@ +object Test { + type PF[A, B] = PartialFunction[A, B] + + val f: PF[Int, String] = { + case i => "bar" + } +}
\ No newline at end of file diff --git a/tests/run/i2077.check b/tests/run/i2077.check new file mode 100644 index 000000000..45b983be3 --- /dev/null +++ b/tests/run/i2077.check @@ -0,0 +1 @@ +hi diff --git a/tests/run/i2077.scala b/tests/run/i2077.scala new file mode 100644 index 000000000..42b629b90 --- /dev/null +++ b/tests/run/i2077.scala @@ -0,0 +1,10 @@ +object Test { + inline val x = true + val y = if (x) 1 else 2 // reduced to val y = 1 + + def main(args: Array[String]): Unit = + if ({ println("hi"); true }) // cannot be reduced + 1 + else + 2 +} |