Skip to content

Commit efae3a3

Browse files
nicolasstuckiodersky
authored andcommitted
Inline error messages.
1 parent 0f4f863 commit efae3a3

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import Symbols._
1010
import Names._
1111
import NameOps._
1212
import Types._
13-
import Flags._
1413
import util.SourcePosition
1514
import config.Settings.Setting
1615
import interfaces.Diagnostic.{ERROR, INFO, WARNING}

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -651,8 +651,12 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
651651
val cond1 = typed(tree.cond, defn.BooleanType)
652652
val thenp1 = typed(tree.thenp, pt.notApplied)
653653
val elsep1 = typed(tree.elsep orElse (untpd.unitLiteral withPos tree.pos), pt.notApplied)
654-
if (thenp1.tpe.topType != elsep1.tpe.topType)
655-
ctx.error(IfElsePhantom(thenp1, elsep1), tree.pos)
654+
if (thenp1.tpe.topType != elsep1.tpe.topType) {
655+
ctx.error(s"""if/else cannot have branches with types in different lattices:
656+
| ${thenp1.tpe.show} of lattice ${thenp1.tpe.topType.show}
657+
| ${elsep1.tpe.show} of lattice ${elsep1.tpe.topType.show}
658+
""".stripMargin, tree.pos)
659+
}
656660
val thenp2 :: elsep2 :: Nil = harmonize(thenp1 :: elsep1 :: Nil)
657661
assignType(cpy.If(tree)(cond1, thenp2, elsep2), thenp2, elsep2)
658662
}
@@ -825,7 +829,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
825829
case _ =>
826830
val sel1 = typedExpr(tree.selector)
827831
if (sel1.tpe.isPhantom)
828-
ctx.error(MatchOnPhantom(), sel1.pos)
832+
ctx.error("Cannot pattern match on phantoms", sel1.pos)
829833
val selType = fullyDefinedType(sel1.tpe, "pattern selector", tree.pos).widen
830834

831835
val cases1 = typedCases(tree.cases, selType, pt.notApplied)
@@ -861,7 +865,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
861865
if (tpdCases.nonEmpty) {
862866
val top = tpdCases.head.tpe.topType
863867
for (tpdCase <- tpdCases if tpdCase.tpe.topType != top)
864-
ctx.error(MatchPhantom(tpdCase, top), tpdCase.pos)
868+
ctx.error(s"Pattern expected case to return a ${top.show} but was ${tpdCase.tpe.show}", tpdCase.pos)
865869
}
866870

867871
tpdCases
@@ -1348,9 +1352,9 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
13481352

13491353
if (cls.classParents.exists(_.classSymbol eq defn.PhantomClass)) {
13501354
if (!cls.is(Module))
1351-
ctx.error(PhantomIsInObject(), cdef.pos)
1355+
ctx.error("Only object can extend scala.Phantom", cdef.pos)
13521356
else if (!cls.owner.is(Module) && !cls.owner.is(Package))
1353-
ctx.error(PhantomObjectIsInPackageOrObject(), cdef.pos)
1357+
ctx.error("An object extending scala.Phantom must be a top level object or in another object.", cdef.pos)
13541358
}
13551359

13561360
// check value class constraints
@@ -1661,17 +1665,23 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
16611665
* this includes Phantom.Any of different universes.
16621666
*/
16631667
def checkedTops(tree: untpd.Tree): Set[Type] = {
1664-
def checkedTops2(tree1: untpd.Tree, tree2: untpd.Tree, msg: => Message, pos: Position): Set[Type] = {
1665-
val allTops = checkedTops(tree1) union checkedTops(tree2)
1666-
if (allTops.size > 1)
1667-
ctx.error(msg, tree.pos)
1668-
allTops
1669-
}
16701668
tree match {
16711669
case TypeBoundsTree(lo, hi) =>
1672-
checkedTops2(lo, hi, PhantomCrossedMixedBounds(lo, hi), tree.pos)
1670+
val allTops = checkedTops(hi) union checkedTops(lo)
1671+
if (allTops.size <= 1) allTops
1672+
else {
1673+
ctx.error("Type can not be bounded at the same time by types in different latices: " +
1674+
allTops.map(_.show).mkString(", "), tree.pos)
1675+
Set.empty
1676+
}
16731677
case untpd.InfixOp(left, op, right) =>
1674-
checkedTops2(left, right, PhantomCrossedMixedBounds(left, right), tree.pos)
1678+
val allTops = checkedTops(left) union checkedTops(right)
1679+
if (allTops.size <= 1) allTops
1680+
else {
1681+
ctx.error(s"Can not use ${op.show} mix types of different lattices: " +
1682+
allTops.map(_.show).mkString(", "), tree.pos)
1683+
Set.empty
1684+
}
16751685
case EmptyTree => Set.empty
16761686
case _ => Set(tree.typeOpt.topType)
16771687
}

0 commit comments

Comments
 (0)