Skip to content

Typer fixes #5017

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

Closed
wants to merge 13 commits into from
Closed
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
13 changes: 0 additions & 13 deletions compiler/src/dotty/tools/dotc/ast/TreeInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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).
*
Expand Down
3 changes: 1 addition & 2 deletions compiler/src/dotty/tools/dotc/core/Phases.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand Down Expand Up @@ -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
Expand Down
6 changes: 0 additions & 6 deletions compiler/src/dotty/tools/dotc/core/quoted/PickledQuotes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion compiler/src/dotty/tools/dotc/transform/TypeTestsCasts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/typer/Implicits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 12 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will they be inferred? I'm unconvinced that

class Siz[T](i: Int)
class Zle extends Siz(1)

and

class Siz[T]
class Zle extends Siz

should be treated differently w/r/t superclass targs.

if (psym.is(Trait) && !cls.is(Trait) && !cls.superClass.isSubClass(psym))
result = maybeCall(result, psym, psym.primaryConstructor.info)
}
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/i1643.scala
Original file line number Diff line number Diff line change
@@ -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
}
Expand Down
7 changes: 7 additions & 0 deletions tests/neg/i5006.scala
Original file line number Diff line number Diff line change
@@ -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]
}
5 changes: 5 additions & 0 deletions tests/neg/i5008.scala
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions tests/neg/i5010.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
class i0 extends Function0 // error
2 changes: 1 addition & 1 deletion tests/neg/parser-stability-16.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class x0[x0] {
val x1 : x0
}
trait x3 extends x0 {
trait x3 extends x0 { // error
x1 = 0 object // error // error
2 changes: 1 addition & 1 deletion tests/neg/parser-stability-7.scala
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 3 additions & 0 deletions tests/neg/t5063.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class A {
super.+("") // error
}
2 changes: 0 additions & 2 deletions tests/pending/neg/i5008

This file was deleted.

2 changes: 1 addition & 1 deletion tests/run/t3613.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
4 changes: 0 additions & 4 deletions tests/untried/neg/t5063.check

This file was deleted.

3 changes: 0 additions & 3 deletions tests/untried/neg/t5063.scala

This file was deleted.