File tree Expand file tree Collapse file tree 4 files changed +31
-1
lines changed
src/compiler/scala/tools/nsc/typechecker Expand file tree Collapse file tree 4 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -664,7 +664,17 @@ trait Namers extends MethodSynthesis {
664
664
665
665
if (suppress) {
666
666
sym setInfo ErrorType
667
+
668
+ // There are two ways in which we exclude the symbol from being added in typedStats::addSynthetics,
669
+ // because we don't know when the completer runs with respect to this loop in addSynthetics
670
+ // for (sym <- scope)
671
+ // for (tree <- context.unit.synthetics.get(sym) if shouldAdd(sym)) {
672
+ // if (!sym.initialize.hasFlag(IS_ERROR))
673
+ // newStats += typedStat(tree)
674
+ // If we're already in the loop, set the IS_ERROR flag and trigger the condition `sym.initialize.hasFlag(IS_ERROR)`
667
675
sym setFlag IS_ERROR
676
+ // Or, if we are not yet in the addSynthetics loop, we can just retract our symbol from the synthetics for this unit.
677
+ companionContext.unit.synthetics -= sym
668
678
669
679
// Don't unlink in an error situation to generate less confusing error messages.
670
680
// Ideally, our error reporting would distinguish overloaded from recursive user-defined apply methods without signature,
Original file line number Diff line number Diff line change @@ -3168,7 +3168,9 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
3168
3168
for (sym <- scope)
3169
3169
// OPT: shouldAdd is usually true. Call it here, rather than in the outer loop
3170
3170
for (tree <- context.unit.synthetics.get(sym) if shouldAdd(sym)) {
3171
- newStats += typedStat(tree) // might add even more synthetics to the scope
3171
+ // if the completer set the IS_ERROR flag, retract the stat (currently only used by applyUnapplyMethodCompleter)
3172
+ if (! sym.initialize.hasFlag(IS_ERROR ))
3173
+ newStats += typedStat(tree) // might add even more synthetics to the scope
3172
3174
context.unit.synthetics -= sym
3173
3175
}
3174
3176
// the type completer of a synthetic might add more synthetics. example: if the
Original file line number Diff line number Diff line change
1
+ trait Companion [T ] {
2
+ def parse (value : String ): Option [T ]
3
+ def apply (value : String ): T = parse(value).get
4
+ }
Original file line number Diff line number Diff line change
1
+ import scala .util .Try
2
+
3
+ object C extends Companion [C ] {
4
+ def parse (v : String ) = if (v.nonEmpty) Some (new C (v)) else None
5
+ }
6
+
7
+ case class C (value : String )
8
+
9
+ object Test {
10
+ def main (args : Array [String ]): Unit = {
11
+ assert(Try {C (" " )}.isFailure, " Empty value should fail to parse" ) // check that parse is used to validate input
12
+ assert(C (" a" ).value == " a" , " Unexpected value" )
13
+ }
14
+ }
You can’t perform that action at this time.
0 commit comments