Skip to content

Commit 104baca

Browse files
committed
---
yaml --- r: 348915 b: refs/heads/master c: 43df5a2 h: refs/heads/master i: 348913: ef3f671 348911: 2ad9bae
1 parent bd62aba commit 104baca

17 files changed

+135
-176
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: bc1a3eaaa5b213fd0f8d5679ac1f905208c44e83
2+
refs/heads/master: 43df5a240e3f08daf8d7c0c78de676d6c8827d11
33
refs/heads/master-next: 203b3026584ecad859eb328b2e12490099409cd5
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea

trunk/include/swift/AST/DiagnosticsSema.def

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3493,8 +3493,6 @@ ERROR(single_tuple_parameter_mismatch_special,none,
34933493
ERROR(single_tuple_parameter_mismatch_normal,none,
34943494
"%0 %1 expects a single parameter of type %2%3",
34953495
(DescriptiveDeclKind, DeclBaseName, Type, StringRef))
3496-
NOTE(note_maybe_forgot_to_form_tuple,none,
3497-
"did you mean to pass a tuple?", ())
34983496
ERROR(unknown_single_tuple_parameter_mismatch,none,
34993497
"single parameter of type %0 is expected in call", (Type))
35003498
ERROR(cannot_convert_single_tuple_into_multiple_arguments,none,

trunk/include/swift/Parse/ASTGen.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class ASTGen {
8181

8282
Expr *generate(const syntax::ExprSyntax &Expr, const SourceLoc Loc);
8383
Expr *generate(const syntax::IdentifierExprSyntax &Expr, const SourceLoc Loc);
84+
Expr *generate(const syntax::SuperRefExprSyntax &Expr, const SourceLoc Loc);
8485
Expr *generate(const syntax::EditorPlaceholderExprSyntax &Expr,
8586
const SourceLoc Loc);
8687
Expr *generate(const syntax::SpecializeExprSyntax &Expr, const SourceLoc Loc);

trunk/include/swift/Parse/Parser.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,6 +1454,7 @@ class Parser {
14541454
ParserResult<Expr> parseExprKeyPath();
14551455
ParserResult<Expr> parseExprSelector();
14561456
ParserResult<Expr> parseExprSuper();
1457+
ParsedSyntaxResult<ParsedExprSyntax> parseExprSuperSyntax();
14571458
ParserResult<Expr> parseExprStringLiteral();
14581459

14591460
// todo [gsoc]: create new result type for ParsedSyntax

trunk/lib/Parse/ASTGen.cpp

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ Expr *ASTGen::generate(const ExprSyntax &E, const SourceLoc Loc) {
234234

235235
if (auto identifierExpr = E.getAs<IdentifierExprSyntax>())
236236
result = generate(*identifierExpr, Loc);
237+
else if (auto superRefExpr = E.getAs<SuperRefExprSyntax>())
238+
result = generate(*superRefExpr, Loc);
237239
else if (auto specializeExpr = E.getAs<SpecializeExprSyntax>())
238240
result = generate(*specializeExpr, Loc);
239241
else if (auto editorPlaceHolderExpr = E.getAs<EditorPlaceholderExprSyntax>())
@@ -256,8 +258,14 @@ Expr *ASTGen::generate(const ExprSyntax &E, const SourceLoc Loc) {
256258
result = generate(*poundFunctionExpr, Loc);
257259
else if (auto poundDsohandleExpr = E.getAs<PoundDsohandleExprSyntax>())
258260
result = generate(*poundDsohandleExpr, Loc);
259-
else
261+
else if (auto unknownExpr = E.getAs<UnknownExprSyntax>())
262+
result = generate(*unknownExpr, Loc);
263+
else {
264+
#ifndef NDEBUG
265+
E.dump();
260266
llvm_unreachable("unsupported expression");
267+
#endif
268+
}
261269

262270
return result;
263271
}
@@ -366,6 +374,39 @@ Expr *ASTGen::generate(const IdentifierExprSyntax &E, const SourceLoc Loc) {
366374
return new (Context) DeclRefExpr(D, nameLoc, /*implicit=*/false);
367375
}
368376

377+
static VarDecl *getImplicitSelfDeclForSuperContext(Parser &P,
378+
DeclContext *DC,
379+
SourceLoc Loc) {
380+
auto *methodContext = DC->getInnermostMethodContext();
381+
if (!methodContext) {
382+
P.diagnose(Loc, diag::super_not_in_class_method);
383+
return nullptr;
384+
}
385+
386+
// Do an actual lookup for 'self' in case it shows up in a capture list.
387+
auto *methodSelf = methodContext->getImplicitSelfDecl();
388+
auto *lookupSelf = P.lookupInScope(P.Context.Id_self);
389+
if (lookupSelf && lookupSelf != methodSelf) {
390+
// FIXME: This is the wrong diagnostic for if someone manually declares a
391+
// variable named 'self' using backticks.
392+
P.diagnose(Loc, diag::super_in_closure_with_capture);
393+
P.diagnose(lookupSelf->getLoc(), diag::super_in_closure_with_capture_here);
394+
return nullptr;
395+
}
396+
397+
return methodSelf;
398+
}
399+
400+
Expr *ASTGen::generate(const SuperRefExprSyntax &E, const SourceLoc Loc) {
401+
auto superLoc = advanceLocBegin(Loc, E.getSuperKeyword());
402+
VarDecl *selfDecl =
403+
getImplicitSelfDeclForSuperContext(P, P.CurDeclContext, superLoc);
404+
if (!selfDecl)
405+
return new (Context) ErrorExpr(superLoc);
406+
407+
return new (Context) SuperRefExpr(selfDecl, superLoc, /*Implicit=*/false);
408+
}
409+
369410
Expr *ASTGen::generate(const EditorPlaceholderExprSyntax &E, const SourceLoc Loc) {
370411
assert(!E.getIdentifier().isMissing());
371412

trunk/lib/Parse/ParseExpr.cpp

Lines changed: 21 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -813,29 +813,6 @@ UnresolvedDeclRefExpr *Parser::parseExprOperator() {
813813
return new (Context) UnresolvedDeclRefExpr(name, refKind, DeclNameLoc(loc));
814814
}
815815

816-
static VarDecl *getImplicitSelfDeclForSuperContext(Parser &P,
817-
DeclContext *DC,
818-
SourceLoc Loc) {
819-
auto *methodContext = DC->getInnermostMethodContext();
820-
if (!methodContext) {
821-
P.diagnose(Loc, diag::super_not_in_class_method);
822-
return nullptr;
823-
}
824-
825-
// Do an actual lookup for 'self' in case it shows up in a capture list.
826-
auto *methodSelf = methodContext->getImplicitSelfDecl();
827-
auto *lookupSelf = P.lookupInScope(P.Context.Id_self);
828-
if (lookupSelf && lookupSelf != methodSelf) {
829-
// FIXME: This is the wrong diagnostic for if someone manually declares a
830-
// variable named 'self' using backticks.
831-
P.diagnose(Loc, diag::super_in_closure_with_capture);
832-
P.diagnose(lookupSelf->getLoc(), diag::super_in_closure_with_capture_here);
833-
return nullptr;
834-
}
835-
836-
return methodSelf;
837-
}
838-
839816
/// parseExprSuper
840817
///
841818
/// expr-super:
@@ -848,28 +825,36 @@ static VarDecl *getImplicitSelfDeclForSuperContext(Parser &P,
848825
/// 'super' '.' 'init'
849826
/// expr-super-subscript:
850827
/// 'super' '[' expr ']'
851-
ParserResult<Expr> Parser::parseExprSuper() {
852-
SyntaxParsingContext SuperCtxt(SyntaxContext, SyntaxContextKind::Expr);
853-
// Parse the 'super' reference.
854-
SourceLoc superLoc = consumeToken(tok::kw_super);
855-
SyntaxContext->createNodeInPlace(SyntaxKind::SuperRefExpr);
828+
ParsedSyntaxResult<ParsedExprSyntax> Parser::parseExprSuperSyntax() {
829+
auto superTok = consumeTokenSyntax(tok::kw_super);
856830

857831
// 'super.' must be followed by a member ref, explicit initializer ref, or
858832
// subscript call.
859833
if (!Tok.isAny(tok::period, tok::period_prefix, tok::code_complete) &&
860834
!Tok.isFollowingLSquare()) {
861-
if (!consumeIf(tok::unknown))
835+
SmallVector<ParsedSyntax, 2> junk;
836+
junk.emplace_back(std::move(superTok));
837+
if (auto unknown = consumeTokenSyntaxIf(tok::unknown)) {
838+
junk.emplace_back(std::move(*unknown));
839+
} else {
862840
diagnose(Tok, diag::expected_dot_or_subscript_after_super);
863-
return nullptr;
841+
}
842+
843+
return makeParsedError(
844+
ParsedSyntaxRecorder::makeUnknownExpr(junk, *SyntaxContext));
864845
}
865846

866-
VarDecl *selfDecl =
867-
getImplicitSelfDeclForSuperContext(*this, CurDeclContext, superLoc);
868-
if (!selfDecl)
869-
return makeParserResult(new (Context) ErrorExpr(superLoc));
847+
return makeParsedResult(ParsedSyntaxRecorder::makeSuperRefExpr(
848+
std::move(superTok), *SyntaxContext));
849+
}
870850

871-
return makeParserResult(new (Context) SuperRefExpr(selfDecl, superLoc,
872-
/*Implicit=*/false));
851+
ParserResult<Expr> Parser::parseExprSuper() {
852+
auto leadingLoc = leadingTriviaLoc();
853+
auto parsed = parseExprSuperSyntax();
854+
SyntaxContext->addSyntax(parsed.get());
855+
auto syntax = SyntaxContext->topNode<ExprSyntax>();
856+
auto expr = Generator.generate(syntax, leadingLoc);
857+
return makeParserResult(parsed.getStatus(), expr);
873858
}
874859

875860
StringRef Parser::copyAndStripUnderscores(StringRef orig) {

trunk/lib/SILGen/SILGenType.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,7 @@ SILGenModule::emitVTableMethod(ClassDecl *theClass,
153153
auto thunk = builder.createFunction(
154154
SILLinkage::Private, name, overrideInfo.SILFnType,
155155
cast<AbstractFunctionDecl>(derivedDecl)->getGenericEnvironment(), loc,
156-
IsBare, IsNotTransparent, IsNotSerialized, IsNotDynamic,
157-
ProfileCounter(), IsThunk);
156+
IsBare, IsNotTransparent, IsNotSerialized, IsNotDynamic);
158157
thunk->setDebugScope(new (M) SILDebugScope(loc, thunk));
159158

160159
PrettyStackTraceSILFunction trace("generating vtable thunk", thunk);

trunk/lib/Sema/CSDiagnostics.cpp

Lines changed: 6 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4880,49 +4880,13 @@ bool InvalidTupleSplatWithSingleParameterFailure::diagnoseAsError() {
48804880
? emitDiagnostic(argExpr->getLoc(),
48814881
diag::single_tuple_parameter_mismatch_special,
48824882
choice->getDescriptiveKind(), paramTy, subsStr)
4883-
: emitDiagnostic(argExpr->getLoc(),
4884-
diag::single_tuple_parameter_mismatch_normal,
4885-
choice->getDescriptiveKind(), name, paramTy, subsStr);
4886-
4887-
4888-
auto newLeftParenLoc = argExpr->getStartLoc();
4889-
if (auto *TE = dyn_cast<TupleExpr>(argExpr)) {
4890-
auto firstArgLabel = TE->getElementName(0);
4891-
// Cover situations like:
4892-
//
4893-
// func foo(x: (Int, Int)) {}
4894-
// foo(x: 0, 1)
4895-
//
4896-
// Where left paren should be suggested after the label,
4897-
// since the label belongs to the parameter itself.
4898-
if (!firstArgLabel.empty()) {
4899-
auto paramTuple = resolveType(ParamType)->castTo<TupleType>();
4900-
// If the label of the first argument matches the one required
4901-
// by the parameter it would be omitted from the fixed parameter type.
4902-
if (!paramTuple->getElement(0).hasName())
4903-
newLeftParenLoc = Lexer::getLocForEndOfToken(getASTContext().SourceMgr,
4904-
TE->getElementNameLoc(0));
4905-
}
4906-
}
4907-
4908-
// If the parameter is a generic parameter, it's hard to say
4909-
// whether use of a tuple is really intended here, so let's
4910-
// attach a fix-it to a note instead of the diagnostic message
4911-
// to indicate that it's not the only right solution possible.
4912-
if (auto *typeVar = ParamType->getAs<TypeVariableType>()) {
4913-
if (typeVar->getImpl().getGenericParameter()) {
4914-
diagnostic.flush();
4915-
4916-
emitDiagnostic(argExpr->getLoc(), diag::note_maybe_forgot_to_form_tuple)
4917-
.fixItInsertAfter(newLeftParenLoc, "(")
4918-
.fixItInsert(argExpr->getEndLoc(), ")");
4919-
}
4920-
} else {
4921-
diagnostic.highlight(argExpr->getSourceRange())
4922-
.fixItInsertAfter(newLeftParenLoc, "(")
4923-
.fixItInsert(argExpr->getEndLoc(), ")");
4924-
}
4883+
: emitDiagnostic(
4884+
argExpr->getLoc(), diag::single_tuple_parameter_mismatch_normal,
4885+
choice->getDescriptiveKind(), name, paramTy, subsStr);
49254886

4887+
diagnostic.highlight(argExpr->getSourceRange())
4888+
.fixItInsertAfter(argExpr->getStartLoc(), "(")
4889+
.fixItInsert(argExpr->getEndLoc(), ")");
49264890
return true;
49274891
}
49284892

trunk/lib/Sema/CSFix.cpp

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -707,42 +707,14 @@ bool AllowTupleSplatForSingleParameter::attempt(
707707

708708
const auto &param = params.front();
709709

710-
if (param.isInOut() || param.isVariadic() || param.isAutoClosure())
711-
return true;
712-
713-
auto paramTy = param.getOldType();
714-
715-
// Parameter type has to be either a tuple (with the same arity as
716-
// argument list), or a type variable.
717-
if (!(paramTy->is<TupleType>() &&
718-
paramTy->castTo<TupleType>()->getNumElements() == args.size()) &&
719-
!paramTy->is<TypeVariableType>())
710+
auto *paramTy = param.getOldType()->getAs<TupleType>();
711+
if (!paramTy || paramTy->getNumElements() != args.size())
720712
return true;
721713

722714
SmallVector<TupleTypeElt, 4> argElts;
723-
724-
for (unsigned index : indices(args)) {
725-
const auto &arg = args[index];
726-
727-
auto label = arg.getLabel();
728-
auto flags = arg.getParameterFlags();
729-
730-
// In situations where there is a single labeled parameter
731-
// we need to form a tuple with omits first label e.g.
732-
//
733-
// func foo<T>(x: T) {}
734-
// foo(x: 0, 1)
735-
//
736-
// We'd want to suggest argument list to be `x: (0, 1)` instead
737-
// of `(x: 0, 1)` which would be incorrect.
738-
if (index == 0 && param.getLabel() == label)
739-
label = Identifier();
740-
741-
// Tuple can't have `inout` elements.
742-
if (flags.isInOut())
743-
return true;
744-
745-
argElts.push_back({arg.getPlainType(), label});
715+
for (const auto &arg : args) {
716+
argElts.push_back(
717+
{arg.getPlainType(), arg.getLabel(), arg.getParameterFlags()});
746718
}
747719

748720
bindings[0].clear();

trunk/test/Constraints/enum_cases.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@ enum E_32551313<L, R> {
104104

105105
struct Foo_32551313 {
106106
static func bar() -> E_32551313<(String, Foo_32551313?), (String, String)>? {
107-
return E_32551313.Left("", Foo_32551313()) // expected-error {{enum case 'Left' expects a single parameter of type 'L' [with L = (String, Foo_32551313?)]}}
108-
// expected-note@-1 {{did you mean to pass a tuple?}} {{28-28=(}} {{46-46=)}}
107+
return E_32551313.Left("", Foo_32551313()) // expected-error {{extra argument in call}}
109108
}
110109
}
111110

0 commit comments

Comments
 (0)