Skip to content

Fix Missing error message on FailureToEliminateExistential #3296

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

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import scala.collection.{ mutable, immutable }
import scala.collection.mutable.ListBuffer
import scala.annotation.switch
import reporting.trace
import dotty.tools.dotc.reporting.diagnostic.messages.FailureToEliminateExistential

object Scala2Unpickler {

Expand Down Expand Up @@ -627,7 +628,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
*/
def elimExistentials(boundSyms: List[Symbol], tp: Type)(implicit ctx: Context): Type = {
// Need to be careful not to run into cyclic references here (observed when
// comiling t247.scala). That's why we avoiud taking `symbol` of a TypeRef
// compiling t247.scala). That's why we avoid taking `symbol` of a TypeRef
// unless names match up.
val isBound = (tp: Type) => {
def refersTo(tp: Type, sym: Symbol): Boolean = tp match {
Expand Down Expand Up @@ -677,11 +678,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
val anyTypes = boundSyms map (_ => defn.AnyType)
val boundBounds = boundSyms map (_.info.bounds.hi)
val tp2 = tp1.subst(boundSyms, boundBounds).subst(boundSyms, anyTypes)
ctx.warning(s"""failure to eliminate existential
|original type : $tp forSome {${ctx.dclsText(boundSyms, "; ").show}
|reduces to : $tp1
|type used instead: $tp2
|proceed at own risk.""".stripMargin)
ctx.warning(FailureToEliminateExistential(tp, tp1, tp2, boundSyms))
tp2
} else tp1
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public enum ErrorMessageID {
ExpectedTypeBoundOrEqualsID,
ClassAndCompanionNameClashID,
TailrecNotApplicableID,
FailureToEliminateExistentialID
;

public int errorNumber() {
Expand Down
20 changes: 16 additions & 4 deletions compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1821,9 +1821,21 @@ object messages {

case class TailrecNotApplicable(method: Symbol)(implicit ctx: Context)
extends Message(TailrecNotApplicableID) {
val kind = "Syntax"
val msg = hl"TailRec optimisation not applicable, $method is neither ${"private"} nor ${"final"}."
val explanation =
hl"A method annotated ${"@tailrec"} must be declared ${"private"} or ${"final"} so it can't be overridden."
val kind = "Syntax"
val msg = hl"TailRec optimisation not applicable, $method is neither ${"private"} nor ${"final"}."
val explanation =
hl"A method annotated ${"@tailrec"} must be declared ${"private"} or ${"final"} so it can't be overridden."
}

case class FailureToEliminateExistential(tp: Type, tp1: Type, tp2: Type, boundSyms: List[Symbol])(implicit ctx: Context)
extends Message(FailureToEliminateExistentialID) {
val kind = "Compatibility"
val msg = "Failure to eliminate existential type. Proceed at own risk."
val explanation = {
val originalType = ctx.dclsText(boundSyms, "; ").show
hl"""original type : $tp forSome ${originalType}
|reduces to : $tp1
|type used instead: $tp2"""
}
}
}