@@ -853,18 +853,23 @@ object Types {
853
853
def goAnd (l : Type , r : Type ) =
854
854
go(l).meet(go(r), pre, safeIntersection = ctx.base.pendingMemberSearches.contains(name))
855
855
856
- def goOr (tp : OrType ) = tp match {
857
- case OrNull (tp1) if Nullables .unsafeNullsEnabled =>
858
- // Selecting `name` from a type `T | Null` is like selecting `name` from `T`, if
859
- // unsafeNulls is enabled. This can throw at runtime, but we trade soundness for usability.
860
- tp1.findMember(name, pre.stripNull, required, excluded)
861
- case _ =>
856
+ def goOr (tp : OrType ) =
857
+ inline def searchAfterJoin =
862
858
// we need to keep the invariant that `pre <: tp`. Branch `union-types-narrow-prefix`
863
859
// achieved that by narrowing `pre` to each alternative, but it led to merge errors in
864
860
// lots of places. The present strategy is instead of widen `tp` using `join` to be a
865
861
// supertype of `pre`.
866
862
go(tp.join)
867
- }
863
+
864
+ if Nullables .unsafeNullsEnabled then tp match
865
+ case OrNull (tp1) if tp1 <:< defn.ObjectType =>
866
+ // Selecting `name` from a type `T | Null` is like selecting `name` from `T`, if
867
+ // unsafeNulls is enabled and T is a subtype of AnyRef.
868
+ // This can throw at runtime, but we trade soundness for usability.
869
+ tp1.findMember(name, pre.stripNull, required, excluded)
870
+ case _ =>
871
+ searchAfterJoin
872
+ else searchAfterJoin
868
873
869
874
val recCount = ctx.base.findMemberCount
870
875
if (recCount >= Config .LogPendingFindMemberThreshold )
0 commit comments