@@ -9,10 +9,12 @@ import util.{FreshNameCreator, SourceFile, NoSource}
99import util .Spans .Span
1010import ast .{tpd , untpd }
1111import tpd .{Tree , TreeTraverser }
12+ import ast .Trees .Import
1213import typer .Nullables
1314import transform .SymUtils ._
1415import core .Decorators ._
1516import config .SourceVersion
17+ import StdNames .nme
1618import scala .annotation .internal .sharable
1719
1820class CompilationUnit protected (val source : SourceFile ) {
@@ -51,6 +53,9 @@ class CompilationUnit protected (val source: SourceFile) {
5153 */
5254 var needsStaging : Boolean = false
5355
56+ /** Will be set to true if the unit contains a captureChecking language import */
57+ var needsCaptureChecking : Boolean = false
58+
5459 var suspended : Boolean = false
5560 var suspendedAtInliningPhase : Boolean = false
5661
@@ -111,6 +116,7 @@ object CompilationUnit {
111116 force.traverse(unit1.tpdTree)
112117 unit1.needsStaging = force.containsQuote
113118 unit1.needsInlining = force.containsInline
119+ unit1.needsCaptureChecking = force.containsCaptureChecking
114120 }
115121 unit1
116122 }
@@ -138,11 +144,17 @@ object CompilationUnit {
138144 private class Force extends TreeTraverser {
139145 var containsQuote = false
140146 var containsInline = false
147+ var containsCaptureChecking = false
141148 def traverse (tree : Tree )(using Context ): Unit = {
142149 if (tree.symbol.isQuote)
143150 containsQuote = true
144151 if tree.symbol.is(Flags .Inline ) then
145152 containsInline = true
153+ tree match
154+ case Import (qual, selectors)
155+ if tpd.languageImport(qual).isDefined && selectors.contains(nme.captureChecking) =>
156+ containsCaptureChecking = true
157+ case _ =>
146158 traverseChildren(tree)
147159 }
148160 }
0 commit comments