@@ -651,8 +651,12 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
651
651
val cond1 = typed(tree.cond, defn.BooleanType )
652
652
val thenp1 = typed(tree.thenp, pt.notApplied)
653
653
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
+ }
656
660
val thenp2 :: elsep2 :: Nil = harmonize(thenp1 :: elsep1 :: Nil )
657
661
assignType(cpy.If (tree)(cond1, thenp2, elsep2), thenp2, elsep2)
658
662
}
@@ -825,7 +829,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
825
829
case _ =>
826
830
val sel1 = typedExpr(tree.selector)
827
831
if (sel1.tpe.isPhantom)
828
- ctx.error(MatchOnPhantom () , sel1.pos)
832
+ ctx.error(" Cannot pattern match on phantoms " , sel1.pos)
829
833
val selType = fullyDefinedType(sel1.tpe, " pattern selector" , tree.pos).widen
830
834
831
835
val cases1 = typedCases(tree.cases, selType, pt.notApplied)
@@ -861,7 +865,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
861
865
if (tpdCases.nonEmpty) {
862
866
val top = tpdCases.head.tpe.topType
863
867
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)
865
869
}
866
870
867
871
tpdCases
@@ -1348,9 +1352,9 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
1348
1352
1349
1353
if (cls.classParents.exists(_.classSymbol eq defn.PhantomClass )) {
1350
1354
if (! cls.is(Module ))
1351
- ctx.error(PhantomIsInObject () , cdef.pos)
1355
+ ctx.error(" Only object can extend scala.Phantom " , cdef.pos)
1352
1356
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)
1354
1358
}
1355
1359
1356
1360
// check value class constraints
@@ -1661,17 +1665,23 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
1661
1665
* this includes Phantom.Any of different universes.
1662
1666
*/
1663
1667
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
- }
1670
1668
tree match {
1671
1669
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
+ }
1673
1677
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
+ }
1675
1685
case EmptyTree => Set .empty
1676
1686
case _ => Set (tree.typeOpt.topType)
1677
1687
}
0 commit comments