diff options
author | Adriaan Moors <adriaan@lightbend.com> | 2017-04-11 16:57:16 -0700 |
---|---|---|
committer | Adriaan Moors <adriaan@lightbend.com> | 2017-04-12 07:51:18 -0700 |
commit | 747e22322330a762dd54037ccc1cb3608c6691bd (patch) | |
tree | 1f18742955bbdc6914c23c739e65f11a738895a3 /src/compiler/scala/tools/nsc/typechecker/Namers.scala | |
parent | 12c240d69b6958d2c8f03a7728c097dd215011cd (diff) | |
download | scala-747e22322330a762dd54037ccc1cb3608c6691bd.tar.gz scala-747e22322330a762dd54037ccc1cb3608c6691bd.tar.bz2 scala-747e22322330a762dd54037ccc1cb3608c6691bd.zip |
Actually retract clashing synthetic apply/unapply
The completer set the IS_ERROR flag and I assumed the typer
dropped a synthetic tree with a symbol with that flag, because
the tree was not shown in -Xprint output.
It turns out, as explained by lrytz, that the mechanism was
fragile because it relied on the order in which completers are
run. We now cover both the case that:
- the completer was run (and the `IS_ERROR` flag was set)
before `addSynthetics` in `typedStat` iterates over the scope
(since the symbol is already unlinked, the tree is not added,
irrespective of its flags). For this case, we also remove the
symbol from the synthetics in its unit.
- the completer is triggered during the iteration in `addSynthetics`,
which needs the check for the `IS_ERROR` flag during the iteration.
Thankfully, the community build caught my mistake, and lrytz provided
a good analysis and review.
Fix scala/bug#10261
Diffstat (limited to 'src/compiler/scala/tools/nsc/typechecker/Namers.scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Namers.scala | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala index bbb9d33140..f69d1d5254 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala @@ -664,7 +664,17 @@ trait Namers extends MethodSynthesis { if (suppress) { sym setInfo ErrorType + + // There are two ways in which we exclude the symbol from being added in typedStats::addSynthetics, + // because we don't know when the completer runs with respect to this loop in addSynthetics + // for (sym <- scope) + // for (tree <- context.unit.synthetics.get(sym) if shouldAdd(sym)) { + // if (!sym.initialize.hasFlag(IS_ERROR)) + // newStats += typedStat(tree) + // If we're already in the loop, set the IS_ERROR flag and trigger the condition `sym.initialize.hasFlag(IS_ERROR)` sym setFlag IS_ERROR + // Or, if we are not yet in the addSynthetics loop, we can just retract our symbol from the synthetics for this unit. + companionContext.unit.synthetics -= sym // Don't unlink in an error situation to generate less confusing error messages. // Ideally, our error reporting would distinguish overloaded from recursive user-defined apply methods without signature, |