Skip to content

Commit bedb33f

Browse files
committed
Don't infer protected members into lub refinements.
Following up to the previous, taking my own advice in SI-5352.
1 parent 14ca7ef commit bedb33f

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

src/compiler/scala/reflect/internal/Types.scala

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2993,6 +2993,9 @@ A type's typeSymbol should never be inspected directly.
29932993

29942994
/** A creator for intersection type where intersections of a single type are
29952995
* replaced by the type itself, and repeated parent classes are merged.
2996+
*
2997+
* !!! Repeated parent classes are not merged - is this a bug in the
2998+
* comment or in the code?
29962999
*/
29973000
def intersectionType(tps: List[Type], owner: Symbol): Type = tps match {
29983001
case List(tp) =>
@@ -5749,9 +5752,16 @@ A type's typeSymbol should never be inspected directly.
57495752
val lubType =
57505753
if (phase.erasedTypes || depth == 0) lubBase
57515754
else {
5752-
val lubRefined = refinedType(lubParents, lubOwner)
5755+
val lubRefined = refinedType(lubParents, lubOwner)
57535756
val lubThisType = lubRefined.typeSymbol.thisType
5754-
val narrowts = ts map (_.narrow)
5757+
val narrowts = ts map (_.narrow)
5758+
def excludeFromLub(sym: Symbol) = (
5759+
sym.isClass
5760+
|| sym.isConstructor
5761+
|| !sym.isPublic
5762+
|| isGetClass(sym)
5763+
|| narrowts.exists(t => !refines(t, sym))
5764+
)
57555765
def lubsym(proto: Symbol): Symbol = {
57565766
val prototp = lubThisType.memberInfo(proto)
57575767
val syms = narrowts map (t =>
@@ -5780,16 +5790,15 @@ A type's typeSymbol should never be inspected directly.
57805790
// efficiency.
57815791
alt != sym && !specializesSym(lubThisType, sym, tp, alt)))
57825792
}
5783-
for (sym <- lubBase.nonPrivateMembers) {
5784-
// add a refinement symbol for all non-class members of lubBase
5785-
// which are refined by every type in ts.
5786-
if (!sym.isClass && !sym.isConstructor && !isGetClass(sym) && (narrowts forall (t => refines(t, sym))))
5787-
try {
5788-
val lsym = lubsym(sym)
5789-
if (lsym != NoSymbol) addMember(lubThisType, lubRefined, lubsym(sym))
5790-
} catch {
5791-
case ex: NoCommonType =>
5792-
}
5793+
// add a refinement symbol for all non-class members of lubBase
5794+
// which are refined by every type in ts.
5795+
for (sym <- lubBase.nonPrivateMembers ; if !excludeFromLub(sym)) {
5796+
try {
5797+
val lsym = lubsym(sym)
5798+
if (lsym != NoSymbol) addMember(lubThisType, lubRefined, lsym)
5799+
} catch {
5800+
case ex: NoCommonType =>
5801+
}
57935802
}
57945803
if (lubRefined.decls.isEmpty) lubBase
57955804
else if (!verifyLubs) lubRefined

0 commit comments

Comments
 (0)