Skip to content

Commit d9df1cd

Browse files
committed
Merge remote-tracking branch 'origin/master' into master-next
2 parents c728714 + 55eb35c commit d9df1cd

File tree

4 files changed

+52
-6
lines changed

4 files changed

+52
-6
lines changed

lib/AST/Type.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,17 @@ swift::decomposeArgType(Type type, ArrayRef<Identifier> argumentLabels) {
785785
parenTy->getParameterFlags()));
786786
return result;
787787
}
788-
788+
789+
// If `Void` has been explicitly specified, resulting decomposition
790+
// should be empty, just like empty tuple would be.
791+
case TypeKind::NameAlias: {
792+
auto &ctx = type->getASTContext();
793+
auto *typealias = cast<NameAliasType>(type.getPointer());
794+
if (typealias->getDecl() == ctx.getVoidDecl())
795+
return result;
796+
break;
797+
}
798+
789799
default:
790800
// Default behavior below; inject the argument as the sole parameter.
791801
break;

lib/Parse/ParseExpr.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,17 @@ ParserResult<Expr> Parser::parseExprSequenceElement(Diag<> message,
463463
return sub;
464464
}
465465

466+
static Expr *formUnaryArgument(ASTContext &context, Expr *argument) {
467+
if (isa<ParenExpr>(argument))
468+
return argument;
469+
470+
auto *arg = new (context)
471+
ParenExpr(argument->getStartLoc(), argument, argument->getEndLoc(),
472+
/*hasTrailingClosure*/ false);
473+
arg->setImplicit();
474+
return arg;
475+
}
476+
466477
/// parseExprUnary
467478
///
468479
/// expr-unary(Mode):
@@ -538,8 +549,8 @@ ParserResult<Expr> Parser::parseExprUnary(Diag<> Message, bool isExprBasic) {
538549
}
539550
}
540551

541-
return makeParserResult(
542-
new (Context) PrefixUnaryExpr(Operator, SubExpr.get()));
552+
return makeParserResult(new (Context) PrefixUnaryExpr(
553+
Operator, formUnaryArgument(Context, SubExpr.get())));
543554
}
544555

545556
/// expr-keypath-swift:
@@ -1330,8 +1341,9 @@ Parser::parseExprPostfixSuffix(ParserResult<Expr> Result, bool isExprBasic,
13301341
break;
13311342

13321343
Expr *oper = parseExprOperator();
1333-
Result =
1334-
makeParserResult(new (Context) PostfixUnaryExpr(oper, Result.get()));
1344+
1345+
Result = makeParserResult(new (Context) PostfixUnaryExpr(
1346+
oper, formUnaryArgument(Context, Result.get())));
13351347
SyntaxContext->createNodeInPlace(SyntaxKind::PostfixUnaryExpr);
13361348
continue;
13371349
}

test/Parse/invalid.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ struct Weak<T: class> { // expected-error {{'class' constraint can only appear o
140140
}
141141

142142
let x: () = ()
143-
!() // expected-error {{missing argument for parameter #1 in call}}
143+
!() // expected-error {{cannot convert value of type '()' to expected argument type 'Bool'}}
144144
!(()) // expected-error {{cannot convert value of type '()' to expected argument type 'Bool'}}
145145
!(x) // expected-error {{cannot convert value of type '()' to expected argument type 'Bool'}}
146146
!x // expected-error {{cannot convert value of type '()' to expected argument type 'Bool'}}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
postfix operator %
4+
postfix func % (_: Any) {}
5+
6+
prefix operator ~
7+
prefix func ~ (_: Any) {}
8+
9+
func foo(_: String) -> Void {}
10+
func foo(_: Int) -> Void {}
11+
12+
_ = foo("answer")% // Ok
13+
_ = ~foo(42) // Ok
14+
15+
class A {
16+
func bar(_: Int) {}
17+
}
18+
19+
extension A {
20+
func bar(_ qux: String) {
21+
bar(qux)% // Ok
22+
~bar(qux) // Ok
23+
}
24+
}

0 commit comments

Comments
 (0)