Skip to content

Commit 6a321ad

Browse files
committed
fix long stable path
1 parent b49aca9 commit 6a321ad

File tree

2 files changed

+13
-22
lines changed

2 files changed

+13
-22
lines changed

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ object Types {
163163
case tp: RefinedOrRecType => tp.parent.isStable
164164
case tp: ExprType => tp.resultType.isStable
165165
case tp: AnnotatedType => tp.parent.isStable
166+
case tp: AndType => tp.tp1.isStable || tp.tp2.isStable
166167
case _ => false
167168
}
168169

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

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -95,36 +95,26 @@ object Nullables with
9595

9696
/** An extractor for null-trackable references */
9797
object TrackedRef
98-
def unapply(tree: Tree)(given Context): Option[TermRef] = isTracked(tree)
98+
def unapply(tree: Tree)(given Context): Option[TermRef] = tree.typeOpt match
99+
case ref: TermRef if isTracked(ref) => println("tr: " + ref); Some(ref)
100+
case _ => None
99101
end TrackedRef
100102

101103
/** Is given reference tracked for nullability?
102104
* This is the case if the reference is a path to an immutable val, or if it refers
103105
* to a local mutable variable where all assignments to the variable are _reachable_
104106
* (in the sense of how it is defined in assignmentSpans).
105107
*/
106-
def isTracked(tree: Tree)(given Context): Option[TermRef] = tree.typeOpt match
107-
case ref: TermRef
108-
if ref.isStable
109-
|| isTrackedNotNull(tree)
108+
def isTracked(ref: TermRef)(given Context) =
109+
ref.isStable
110110
|| { val sym = ref.symbol
111-
sym.is(Mutable)
112-
&& sym.owner.isTerm
113-
&& sym.owner.enclosingMethod == curCtx.owner.enclosingMethod
114-
&& sym.span.exists
115-
&& curCtx.compilationUnit != null // could be null under -Ytest-pickler
116-
&& curCtx.compilationUnit.assignmentSpans.contains(sym.span.start)
117-
} =>
118-
Some(ref)
119-
case _ => None
120-
121-
def isTrackedNotNull(tree: Tree)(given Context) = tree match
122-
case Select(Apply(TypeApply(f: Ident, _), x :: Nil), _) =>
123-
f.symbol == defn.Compiletime_notNull
124-
&& tree.symbol.isStableMember
125-
&& isTracked(x).isDefined
126-
case _ =>
127-
false
111+
sym.is(Mutable)
112+
&& sym.owner.isTerm
113+
&& sym.owner.enclosingMethod == curCtx.owner.enclosingMethod
114+
&& sym.span.exists
115+
&& curCtx.compilationUnit != null // could be null under -Ytest-pickler
116+
&& curCtx.compilationUnit.assignmentSpans.contains(sym.span.start)
117+
}
128118

129119
/** The nullability context to be used after a case that matches pattern `pat`.
130120
* If `pat` is `null`, this will assert that the selector `sel` is not null afterwards.

0 commit comments

Comments
 (0)