diff --git a/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala b/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala index 2e1b674b895e..9cde7305300f 100644 --- a/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala +++ b/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala @@ -542,19 +542,6 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] => case _ => false } - /** Strips layers of `.asInstanceOf[T]` / `_.$asInstanceOf[T]()` from an expression */ - def stripCast(tree: Tree)(implicit ctx: Context): Tree = { - def isCast(sel: Tree) = sel.symbol == defn.Any_asInstanceOf - unsplice(tree) match { - case TypeApply(sel @ Select(inner, _), _) if isCast(sel) => - stripCast(inner) - case Apply(TypeApply(sel @ Select(inner, _), _), Nil) if isCast(sel) => - stripCast(inner) - case t => - t - } - } - /** Decompose a call fn[targs](vargs_1)...(vargs_n) * into its constituents (fn, targs, vargss). * diff --git a/compiler/src/dotty/tools/dotc/core/Phases.scala b/compiler/src/dotty/tools/dotc/core/Phases.scala index 0269c6f536ee..33c5808a0000 100644 --- a/compiler/src/dotty/tools/dotc/core/Phases.scala +++ b/compiler/src/dotty/tools/dotc/core/Phases.scala @@ -84,7 +84,6 @@ object Phases { phasesToSkip: List[String], stopBeforePhases: List[String], stopAfterPhases: List[String], YCheckAfter: List[String]): List[Phase] = { val squashedPhases = ListBuffer[Phase]() var prevPhases: Set[String] = Set.empty - val YCheckAll = YCheckAfter.contains("all") var stop = false val filteredPhases = phasess.map(_.filter { p => @@ -120,7 +119,7 @@ object Phases { phase } squashedPhases += phaseToAdd - val shouldAddYCheck = YCheckAfter.containsPhase(phaseToAdd) || YCheckAll + val shouldAddYCheck = YCheckAfter.containsPhase(phaseToAdd) if (shouldAddYCheck) { val checker = new TreeChecker squashedPhases += checker diff --git a/compiler/src/dotty/tools/dotc/core/quoted/PickledQuotes.scala b/compiler/src/dotty/tools/dotc/core/quoted/PickledQuotes.scala index bedcd8c05724..eaa3684d03c8 100644 --- a/compiler/src/dotty/tools/dotc/core/quoted/PickledQuotes.scala +++ b/compiler/src/dotty/tools/dotc/core/quoted/PickledQuotes.scala @@ -22,12 +22,6 @@ import scala.reflect.ClassTag object PickledQuotes { import tpd._ - /** Pickle the tree of the quoted.Expr */ - def pickleExpr(tree: Tree)(implicit ctx: Context): scala.quoted.Expr[Any] = { - val pickled = pickleQuote(tree) - scala.runtime.quoted.Unpickler.unpickleExpr(pickled, Nil) - } - /** Pickle the tree of the quote into strings */ def pickleQuote(tree: Tree)(implicit ctx: Context): scala.runtime.quoted.Unpickler.Pickled = { if (ctx.reporter.hasErrors) Nil diff --git a/compiler/src/dotty/tools/dotc/transform/TypeTestsCasts.scala b/compiler/src/dotty/tools/dotc/transform/TypeTestsCasts.scala index 1bffe1372586..5c8af165788d 100644 --- a/compiler/src/dotty/tools/dotc/transform/TypeTestsCasts.scala +++ b/compiler/src/dotty/tools/dotc/transform/TypeTestsCasts.scala @@ -140,7 +140,15 @@ object TypeTestsCasts { } def interceptTypeApply(tree: TypeApply)(implicit ctx: Context): Tree = trace(s"transforming ${tree.show}", show = true) { - tree.fun match { + interceptTypeApply1(tree, tree.fun match { + case i: Ident => + desugarIdent(i).withPos(tree.fun) + case t => t + }) + } + + private def interceptTypeApply1(tree: TypeApply, treeFun: Tree)(implicit ctx: Context): Tree = { + treeFun match { case fun @ Select(expr, selector) => val sym = tree.symbol diff --git a/compiler/src/dotty/tools/dotc/typer/Implicits.scala b/compiler/src/dotty/tools/dotc/typer/Implicits.scala index feb6bc391a55..546cce74aaf7 100644 --- a/compiler/src/dotty/tools/dotc/typer/Implicits.scala +++ b/compiler/src/dotty/tools/dotc/typer/Implicits.scala @@ -552,6 +552,7 @@ trait Implicits { self: Typer => || (from.tpe isRef defn.NothingClass) || (from.tpe isRef defn.NullClass) || !(ctx.mode is Mode.ImplicitsEnabled) + || from.isInstanceOf[Super] || (from.tpe eq NoPrefix)) NoMatchingImplicitsFailure else { def adjust(to: Type) = to.stripTypeVar.widenExpr match { diff --git a/compiler/src/dotty/tools/dotc/typer/Namer.scala b/compiler/src/dotty/tools/dotc/typer/Namer.scala index f8d83964e82b..0d116a5ea47c 100644 --- a/compiler/src/dotty/tools/dotc/typer/Namer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Namer.scala @@ -1158,8 +1158,9 @@ class Namer { typer: Typer => /** The type signature of a DefDef with given symbol */ def defDefSig(ddef: DefDef, sym: Symbol)(implicit ctx: Context) = { - val DefDef(name, tparams, vparamss, _, _) = ddef - val isConstructor = name == nme.CONSTRUCTOR + // Beware: ddef.name need not match sym.name if sym was freshened! + val DefDef(_, tparams, vparamss, _, _) = ddef + val isConstructor = sym.name == nme.CONSTRUCTOR // The following 3 lines replace what was previously just completeParams(tparams). // But that can cause bad bounds being computed, as witnessed by diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 240999864503..d5eb642d4336 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -355,7 +355,7 @@ class Typer extends Namer } // begin typedIdent - def kind = if (name.isTermName) "" else "type " + def kind = if (name.isTermName) "value " else "type " typr.println(s"typed ident $kind$name in ${ctx.owner}") if (ctx.mode is Mode.Pattern) { if (name == nme.WILDCARD) @@ -1524,6 +1524,7 @@ class Typer extends Namer ctx.error(i"$psym is extended twice", tree.pos) seenParents += psym if (tree.isType) { + checkSimpleKinded(result) // Not needed for constructor calls, as type arguments will be inferred. if (psym.is(Trait) && !cls.is(Trait) && !cls.superClass.isSubClass(psym)) result = maybeCall(result, psym, psym.primaryConstructor.info) } @@ -1576,6 +1577,15 @@ class Typer extends Namer if (!cls.is(AbstractOrTrait) && !ctx.isAfterTyper) checkRealizableBounds(cls, cdef.namePos) if (cls.is(Case) && cls.derivesFrom(defn.EnumClass)) checkEnum(cdef, cls) + if (seenParents.contains(defn.EnumClass)) { + // Since enums are classes and Namer checks that classes don't extend multiple classes, we only check the class + // parent. + val firstParent = parents1.head.tpe.dealias.typeSymbol + if (firstParent.derivesFrom(defn.EnumClass)) + //Tricky to phrase; language taken from "case-to-case inheritance is prohibited". + ctx.error(s"Enum ${cls.name} has enum ancestor ${firstParent.name}, but enum-to-enum inheritance is prohibited", cdef.pos) + } + val cdef1 = assignType(cpy.TypeDef(cdef)(name, impl1), cls) if (ctx.phase.isTyper && cdef1.tpe.derivesFrom(defn.DynamicClass) && !ctx.dynamicsEnabled) { val isRequired = parents1.exists(_.tpe.isRef(defn.DynamicClass)) @@ -1793,7 +1803,7 @@ class Typer extends Namer case none => def typedNamed(tree: untpd.NameTree, pt: Type)(implicit ctx: Context): Tree = { - val sym = retrieveSym(xtree) + val sym = retrieveSym(tree) tree match { case tree: untpd.Ident => typedIdent(tree, pt) case tree: untpd.Select => typedSelect(tree, pt) diff --git a/tests/neg/i1643.scala b/tests/neg/i1643.scala index 889233b3a0ca..1e3affa7f1c9 100644 --- a/tests/neg/i1643.scala +++ b/tests/neg/i1643.scala @@ -1,4 +1,4 @@ -trait T extends Array { // error +trait T extends Array { // error // error def t1(as: String*): Array[String] = { varargs1(as: _*) } // error def t2(as: String*): Array[String] = { super.varargs1(as: _*) } // error } diff --git a/tests/neg/i5006.scala b/tests/neg/i5006.scala new file mode 100644 index 000000000000..94169286322e --- /dev/null +++ b/tests/neg/i5006.scala @@ -0,0 +1,7 @@ +object i0 { + // Adding anything in front of asInstanceOf, + // i0 or this, makes the error go away. + def i1: Int = asInstanceOf[Int].toInt + + val i2 = asInstanceOf[Int] +} diff --git a/tests/neg/i5008.scala b/tests/neg/i5008.scala new file mode 100644 index 000000000000..2c856a07c334 --- /dev/null +++ b/tests/neg/i5008.scala @@ -0,0 +1,5 @@ +enum Foo { case A } +enum Bar { case A } +enum Baz extends Foo { case Z } // error + +enum Quux extends Foo with Bar { case Z } // error diff --git a/tests/neg/i5010.scala b/tests/neg/i5010.scala new file mode 100644 index 000000000000..7cdf67c8135b --- /dev/null +++ b/tests/neg/i5010.scala @@ -0,0 +1 @@ +class i0 extends Function0 // error diff --git a/tests/neg/parser-stability-16.scala b/tests/neg/parser-stability-16.scala index f6f6f19aa890..25fb38374c45 100644 --- a/tests/neg/parser-stability-16.scala +++ b/tests/neg/parser-stability-16.scala @@ -1,5 +1,5 @@ class x0[x0] { val x1 : x0 } -trait x3 extends x0 { +trait x3 extends x0 { // error x1 = 0 object // error // error diff --git a/tests/neg/parser-stability-7.scala b/tests/neg/parser-stability-7.scala index 98ed2cb009a1..27d391ed9396 100644 --- a/tests/neg/parser-stability-7.scala +++ b/tests/neg/parser-stability-7.scala @@ -1,7 +1,7 @@ class x0[x1] { def x2: x1 } -trait x3 extends x0 { +trait x3 extends x0 { // error class x2 var x2 = 0 // error var x4 = x5 x2 // error diff --git a/tests/neg/t5063.scala b/tests/neg/t5063.scala new file mode 100644 index 000000000000..0566e90798f5 --- /dev/null +++ b/tests/neg/t5063.scala @@ -0,0 +1,3 @@ +class A { + super.+("") // error +} diff --git a/tests/pending/neg/i5008 b/tests/pending/neg/i5008 deleted file mode 100644 index 2dc75e6b199c..000000000000 --- a/tests/pending/neg/i5008 +++ /dev/null @@ -1,2 +0,0 @@ -enum Foo {} -enum Bar extends Foo {} // error diff --git a/tests/run/t3613.scala b/tests/run/t3613.scala index 1293f62c0fd4..199ed2ee1933 100644 --- a/tests/run/t3613.scala +++ b/tests/run/t3613.scala @@ -2,7 +2,7 @@ class Boopy { private val s = new Schnuck def observer : PartialFunction[ Any, Unit ] = s.observer - private class Schnuck extends javax.swing.AbstractListModel { + private class Schnuck extends javax.swing.AbstractListModel[Nothing] { model => val observer : PartialFunction[ Any, Unit ] = { case "Boopy" => fireIntervalAdded( model, 0, 1 ) diff --git a/tests/untried/neg/t5063.check b/tests/untried/neg/t5063.check deleted file mode 100644 index c6e553c1b5f6..000000000000 --- a/tests/untried/neg/t5063.check +++ /dev/null @@ -1,4 +0,0 @@ -t5063.scala:2: error: value + is not a member of AnyRef - super.+("") - ^ -one error found diff --git a/tests/untried/neg/t5063.scala b/tests/untried/neg/t5063.scala deleted file mode 100644 index 5b34b53fb7fc..000000000000 --- a/tests/untried/neg/t5063.scala +++ /dev/null @@ -1,3 +0,0 @@ -class A { - super.+("") -}