@@ -890,6 +890,19 @@ class TypeComparer(initctx: Context) extends DotClass {
890
890
891
891
/** Try to distribute `&` inside type, detect and handle conflicts */
892
892
private def distributeAnd (tp1 : Type , tp2 : Type ): Type = tp1 match {
893
+ // opportunistically merge same-named refinements
894
+ // this does not change anything semantically (i.e. merging or not merging
895
+ // gives =:= types), but it keeps the type smaller.
896
+ case tp1 : RefinedType =>
897
+ tp2 match {
898
+ case tp2 : RefinedType if tp1.refinedName == tp2.refinedName =>
899
+ tp1.derivedRefinedType(
900
+ tp1.parent & tp2.parent,
901
+ tp1.refinedName,
902
+ tp1.refinedInfo & tp2.refinedInfo)
903
+ case _ =>
904
+ NoType
905
+ }
893
906
case tp1 : TypeBounds =>
894
907
tp2 match {
895
908
case tp2 : TypeBounds => tp1 & tp2
@@ -935,18 +948,6 @@ class TypeComparer(initctx: Context) extends DotClass {
935
948
case _ =>
936
949
rt1 & tp2
937
950
}
938
- case tp1 : RefinedType =>
939
- // opportunistically merge same-named refinements
940
- // this does not change anything semantically (i.e. merging or not merging
941
- // gives =:= types), but it keeps the type smaller.
942
- tp2 match {
943
- case tp2 : RefinedType if tp1.refinedName == tp2.refinedName =>
944
- tp1.derivedRefinedType(
945
- tp1.parent & tp2.parent, tp1.refinedName,
946
- tp1.refinedInfo & tp2.refinedInfo)
947
- case _ =>
948
- NoType
949
- }
950
951
case tp1 : TypeVar if tp1.isInstantiated =>
951
952
tp1.underlying & tp2
952
953
case tp1 : AnnotatedType =>
@@ -957,6 +958,16 @@ class TypeComparer(initctx: Context) extends DotClass {
957
958
958
959
/** Try to distribute `|` inside type, detect and handle conflicts */
959
960
private def distributeOr (tp1 : Type , tp2 : Type ): Type = tp1 match {
961
+ case tp1 : RefinedType =>
962
+ tp2 match {
963
+ case tp2 : RefinedType if tp1.refinedName == tp2.refinedName =>
964
+ tp1.derivedRefinedType(
965
+ tp1.parent | tp2.parent,
966
+ tp1.refinedName,
967
+ tp1.refinedInfo | tp2.refinedInfo)
968
+ case _ =>
969
+ NoType
970
+ }
960
971
case tp1 : TypeBounds =>
961
972
tp2 match {
962
973
case tp2 : TypeBounds => tp1 | tp2
0 commit comments