@@ -2,7 +2,7 @@ package dotty.tools
2
2
package dotc
3
3
package core
4
4
5
- import SymDenotations .{ SymDenotation , ClassDenotation , NoDenotation }
5
+ import SymDenotations .{ SymDenotation , ClassDenotation , NoDenotation , NotDefinedHereDenotation }
6
6
import Contexts .{Context , ContextBase }
7
7
import Names .{Name , PreName }
8
8
import Names .TypeName
@@ -128,7 +128,17 @@ object Denotations {
128
128
*/
129
129
def atSignature (sig : Signature , site : Type = NoPrefix )(implicit ctx : Context ): SingleDenotation
130
130
131
- /** The variant of this denotation that's current in the given context. */
131
+ /** The variant of this denotation that's current in the given context, or
132
+ * `NotDefinedHereDenotation` if this denotation does not exist at current phase, but
133
+ * is defined elsewhere in this run.
134
+ */
135
+ def currentIfExists (implicit ctx : Context ): Denotation
136
+
137
+ /** The variant of this denotation that's current in the given context.
138
+ * If no such denotation exists: If Mode.FutureDefs is set, the
139
+ * denotation with each alternative at its first point of definition,
140
+ * otherwise a `NotDefinedHere` exception is thrown.
141
+ */
132
142
def current (implicit ctx : Context ): Denotation
133
143
134
144
/** Is this denotation different from NoDenotation or an ErrorDenotation? */
@@ -349,6 +359,8 @@ object Denotations {
349
359
final def signature (implicit ctx : Context ) = Signature .OverloadedSignature
350
360
def atSignature (sig : Signature , site : Type )(implicit ctx : Context ): SingleDenotation =
351
361
denot1.atSignature(sig, site) orElse denot2.atSignature(sig, site)
362
+ def currentIfExists (implicit ctx : Context ): Denotation =
363
+ derivedMultiDenotation(denot1.currentIfExists, denot2.currentIfExists)
352
364
def current (implicit ctx : Context ): Denotation =
353
365
derivedMultiDenotation(denot1.current, denot2.current)
354
366
def altsWith (p : Symbol => Boolean ): List [SingleDenotation ] =
@@ -530,7 +542,7 @@ object Denotations {
530
542
* is brought forward to be valid in the new runId. Otherwise
531
543
* the symbol is stale, which constitutes an internal error.
532
544
*/
533
- def current (implicit ctx : Context ): SingleDenotation = {
545
+ def currentIfExists (implicit ctx : Context ): SingleDenotation = {
534
546
val currentPeriod = ctx.period
535
547
val valid = myValidFor
536
548
if (valid.code <= 0 ) {
@@ -593,17 +605,24 @@ object Denotations {
593
605
// println(s"searching: $cur at $currentPeriod, valid for ${cur.validFor}")
594
606
cur = cur.nextInRun
595
607
cnt += 1
596
- if (cnt > MaxPossiblePhaseId )
597
- if (ctx.mode is Mode .FutureDefsOK )
598
- return current(ctx.withPhase(coveredInterval.firstPhaseId))
599
- else
600
- throw new NotDefinedHere (demandOutsideDefinedMsg)
608
+ if (cnt > MaxPossiblePhaseId ) return NotDefinedHereDenotation
601
609
}
602
610
cur
603
611
}
604
612
}
605
613
}
606
614
615
+ def current (implicit ctx : Context ): SingleDenotation = {
616
+ val d = currentIfExists
617
+ if (d ne NotDefinedHereDenotation ) d else currentNoDefinedHere
618
+ }
619
+
620
+ private def currentNoDefinedHere (implicit ctx : Context ): SingleDenotation =
621
+ if (ctx.mode is Mode .FutureDefsOK )
622
+ current(ctx.withPhase(coveredInterval.firstPhaseId))
623
+ else
624
+ throw new NotDefinedHere (demandOutsideDefinedMsg)
625
+
607
626
private def demandOutsideDefinedMsg (implicit ctx : Context ): String =
608
627
s " demanding denotation of $this at phase ${ctx.phase}( ${ctx.phaseId}) outside defined interval: defined periods are ${definedPeriodsString}"
609
628
0 commit comments