Skip to content
Merged
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
5 changes: 3 additions & 2 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,9 @@ object Types {
/** Is this type produced as a repair for an error? */
final def isError(implicit ctx: Context): Boolean = stripTypeVar.isInstanceOf[ErrorType]

/** Is some part of this type produced as a repair for an error? */
def isErroneous(implicit ctx: Context): Boolean = existsPart(_.isError, forceLazy = false)
/** Is some part of the widened version of this type produced as a repair for an error? */
def isErroneous(implicit ctx: Context): Boolean =
widen.existsPart(_.isError, forceLazy = false)

/** Does the type carry an annotation that is an instance of `cls`? */
@tailrec final def hasAnnotation(cls: ClassSymbol)(implicit ctx: Context): Boolean = stripTypeVar match {
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ object ProtoTypes {
def isDropped: Boolean = state.toDrop

override def isErroneous(implicit ctx: Context): Boolean =
state.typedArgs.tpes.exists(_.widen.isErroneous)
state.typedArgs.tpes.exists(_.isErroneous)

override def toString: String = s"FunProto(${args mkString ","} => $resultType)"

Expand Down
5 changes: 3 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ class Typer extends Namer
val ptDefined = isFullyDefined(pt, ForceDegree.none)
if (ptDefined && !(avoidingType <:< pt)) avoidingType = pt
val tree1 = ascribeType(tree, avoidingType)
assert(ptDefined || noLeaks(tree1) || tree1.tpe.widen.isErroneous,
assert(ptDefined || noLeaks(tree1) || tree1.tpe.isErroneous,
// `ptDefined` needed because of special case of anonymous classes
i"leak: ${escapingRefs(tree1, localSyms).toList}%, % in $tree1")
tree1
Expand Down Expand Up @@ -2897,7 +2897,8 @@ class Typer extends Namer
}

private def checkStatementPurity(tree: tpd.Tree)(original: untpd.Tree, exprOwner: Symbol)(implicit ctx: Context): Unit = {
if (!ctx.isAfterTyper && isPureExpr(tree) && !tree.tpe.isRef(defn.UnitClass) && !isSelfOrSuperConstrCall(tree))
if (!tree.tpe.isErroneous && !ctx.isAfterTyper && isPureExpr(tree) &&
!tree.tpe.isRef(defn.UnitClass) && !isSelfOrSuperConstrCall(tree))
ctx.warning(PureExpressionInStatementPosition(original, exprOwner), original.sourcePos)
}
}
4 changes: 4 additions & 0 deletions tests/neg-custom-args/fatal-warnings/pureStatement.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@ object Test {
2 // error: pure expression does nothing in statement position

doSideEffects(1) // error: pure expression does nothing in statement position

val broken = new IDontExist("") // error // error
broken.foo // no extra error, and no pure expression warning
broken.foo() // same
}