mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Introduce "inherited" default arguments and use them for inherited initializers.
Previously, we were cloning the default arguments completely, which meant code duplication (when inheriting within a module) or simply a failure (when inheriting across modules). Now, we reference the default arguments where we inherited them, eliminating the duplication. Part of <rdar://problem/16318855>. Swift SVN r15062
This commit is contained in:
@@ -222,10 +222,21 @@ Pattern *Pattern::clone(ASTContext &context,
|
||||
auto tuple = cast<TuplePattern>(this);
|
||||
SmallVector<TuplePatternElt, 2> elts;
|
||||
elts.reserve(tuple->getNumFields());
|
||||
for (const auto &elt : tuple->getFields())
|
||||
elts.push_back(TuplePatternElt(elt.getPattern()->clone(context, options),
|
||||
elt.getInit(),
|
||||
elt.getDefaultArgKind()));
|
||||
for (const auto &elt : tuple->getFields()) {
|
||||
auto eltPattern = elt.getPattern()->clone(context, options);
|
||||
|
||||
// If we're inheriting a default argument, mark it as such.
|
||||
if (elt.getDefaultArgKind() != DefaultArgumentKind::None &&
|
||||
(options & Inherited)) {
|
||||
elts.push_back(TuplePatternElt(eltPattern, nullptr,
|
||||
DefaultArgumentKind::Inherited));
|
||||
} else {
|
||||
elts.push_back(TuplePatternElt(eltPattern,
|
||||
elt.getInit(),
|
||||
elt.getDefaultArgKind()));
|
||||
}
|
||||
}
|
||||
|
||||
result = TuplePattern::create(context, tuple->getLParenLoc(), elts,
|
||||
tuple->getRParenLoc(),
|
||||
tuple->hasVararg(),
|
||||
|
||||
Reference in New Issue
Block a user