@@ -691,8 +691,21 @@ trait Namers extends MethodSynthesis {
691691
692692 if (suppress) {
693693 sym setInfo ErrorType
694+ // There are two ways in which we exclude the symbol from being added in typedStats::addSynthetics,
695+ // because we don't know when the completer runs with respect to this loop in addSynthetics
696+ // for (sym <- scope)
697+ // for (tree <- context.unit.synthetics.get(sym) if shouldAdd(sym)) {
698+ // if (!sym.initialize.hasFlag(IS_ERROR))
699+ // newStats += typedStat(tree)
700+ // (1) If we're already in the loop, set the IS_ERROR flag and trigger the condition
701+ // `sym.initialize.hasFlag(IS_ERROR)` in typedStats::addSynthetics,
702+ // (2) Or, if we are not yet in the addSynthetics loop (and we're not going to emit an error anyway),
703+ // we unlink the symbol from its scope.
694704 sym setFlag IS_ERROR
695705
706+ // For good measure. Removing it from its owner's scope and setting the IS_ERROR flag is enough to exclude it from addSynthetics
707+ companionContext.unit.synthetics -= sym
708+
696709 // Don't unlink in an error situation to generate less confusing error messages.
697710 // Ideally, our error reporting would distinguish overloaded from recursive user-defined apply methods without signature,
698711 // but this would require some form of partial-completion of method signatures, so that we can
@@ -702,7 +715,7 @@ trait Namers extends MethodSynthesis {
702715 // I hesitate to provide more info, because it would involve a WildCard or something for its result type,
703716 // which could upset other code paths)
704717 if (! scopePartiallyCompleted)
705- companionContext.scope.unlink(sym)
718+ companionContext.scope.unlink(sym) // (2)
706719 }
707720 }
708721 }
@@ -770,7 +783,7 @@ trait Namers extends MethodSynthesis {
770783 val completer =
771784 if (sym hasFlag SYNTHETIC ) {
772785 if (name == nme.copy) copyMethodCompleter(tree)
773- else if (sym hasFlag CASE ) applyUnapplyMethodCompleter(tree, context)
786+ else if (settings.isScala212 && ( sym hasFlag CASE ) ) applyUnapplyMethodCompleter(tree, context)
774787 else completerOf(tree)
775788 } else completerOf(tree)
776789
0 commit comments