Skip to content

Commit 13e4439

Browse files
bracevacnoti0na1
authored andcommitted
Report error in Setup for illegal capture refs
1 parent bdbb0ba commit 13e4439

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Diff for: compiler/src/dotty/tools/dotc/cc/Setup.scala

+6-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import reporting.Message
1818
import printing.{Printer, Texts}, Texts.{Text, Str}
1919
import collection.mutable
2020
import CCState.*
21+
import dotty.tools.dotc.util.NoSourcePosition
2122

2223
/** Operations accessed from CheckCaptures */
2324
trait SetupAPI:
@@ -323,7 +324,11 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
323324
val parent2 = stripImpliedCaptureSet(parent1)
324325
for tpt <- tptToCheck do
325326
checkWellformedLater(parent2, ann.tree, tpt)
326-
CapturingType(parent2, ann.tree.toCaptureSet)
327+
try
328+
CapturingType(parent2, ann.tree.toCaptureSet)
329+
catch case ex: IllegalCaptureRef =>
330+
report.error(em"Illegal capture reference: ${ex.getMessage.nn}", tptToCheck.fold(NoSourcePosition)(_.srcPos))
331+
t
327332
else
328333
t.derivedAnnotatedType(parent1, ann)
329334
case throwsAlias(res, exc) =>

0 commit comments

Comments
 (0)