Skip to content

Commit 7067a16

Browse files
committed
---
yaml --- r: 348722 b: refs/heads/master c: e7e45fd h: refs/heads/master
1 parent dfb8581 commit 7067a16

File tree

4 files changed

+29
-17
lines changed

4 files changed

+29
-17
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: dc3f110f608c87dcce4f8d3a3f9e52bdc9001dad
2+
refs/heads/master: e7e45fd311607b896efeb4cddf0fa29f1ccde452
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/lib/Parse/ParseType.cpp

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,22 +1084,28 @@ ParsedSyntaxResult<ParsedTypeSyntax> Parser::parseTypeTupleBody() {
10841084
return ty.getStatus();
10851085
}
10861086

1087-
if (IsInOutObsoleted) {
1088-
bool IsTypeAlreadyAttributed = false;
1089-
if (auto AttributedType = ty.getAs<ParsedAttributedTypeSyntax>()) {
1090-
IsTypeAlreadyAttributed =
1091-
AttributedType->getDeferredSpecifier().hasValue();
1092-
ty = makeParsedResult(std::move(*AttributedType), ty.getStatus());
1093-
}
1094-
1095-
if (IsTypeAlreadyAttributed) {
1096-
// If the parsed type is already attributed, suggest removing `inout`.
1097-
diagnose(Tok, diag::parameter_specifier_repeated)
1098-
.fixItRemove(InOutLoc);
1087+
if (InOut) {
1088+
if (IsInOutObsoleted) {
1089+
bool IsTypeAlreadyAttributed = false;
1090+
if (auto AttributedType = ty.getAs<ParsedAttributedTypeSyntax>()) {
1091+
IsTypeAlreadyAttributed =
1092+
AttributedType->getDeferredSpecifier().hasValue();
1093+
ty = makeParsedResult(std::move(*AttributedType), ty.getStatus());
1094+
}
1095+
if (IsTypeAlreadyAttributed) {
1096+
// If the parsed type is already attributed, suggest removing `inout`.
1097+
diagnose(Tok, diag::parameter_specifier_repeated)
1098+
.fixItRemove(InOutLoc);
1099+
} else {
1100+
diagnose(InOutLoc, diag::parameter_specifier_as_attr_disallowed, "inout")
1101+
.fixItRemove(InOutLoc)
1102+
.fixItInsert(TypeLoc, "inout ");
1103+
}
10991104
} else {
1100-
diagnose(InOutLoc, diag::parameter_specifier_as_attr_disallowed, "inout")
1101-
.fixItRemove(InOutLoc)
1102-
.fixItInsert(TypeLoc, "inout ");
1105+
// Apply 'inout' to the parsed type.
1106+
ParsedAttributedTypeSyntaxBuilder builder(*SyntaxContext);
1107+
ty = applyAttributeToTypeSyntax(std::move(ty), std::move(InOut), None);
1108+
InOut.reset();
11031109
}
11041110
}
11051111

trunk/test/Syntax/Outputs/round_trip_parse_gen.swift.withkinds

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,10 @@ typealias G <TypeInitializerClause>= <FunctionType>(<TupleTypeElement>a x: <Simp
142142
typealias H <TypeInitializerClause>= <FunctionType>() rethrows -> <TupleType>()</TupleType></FunctionType></TypeInitializerClause></TypealiasDecl><TypealiasDecl>
143143
typealias I <TypeInitializerClause>= <FunctionType>(<TupleTypeElement><CompositionType><CompositionTypeElement><SimpleTypeIdentifier>A </SimpleTypeIdentifier>& </CompositionTypeElement><CompositionTypeElement><SimpleTypeIdentifier>B<GenericArgumentClause><<GenericArgument><SimpleTypeIdentifier>C</SimpleTypeIdentifier></GenericArgument>></GenericArgumentClause></SimpleTypeIdentifier></CompositionTypeElement></CompositionType></TupleTypeElement>) -> <CompositionType><CompositionTypeElement><SimpleTypeIdentifier>C </SimpleTypeIdentifier>& </CompositionTypeElement><CompositionTypeElement><SimpleTypeIdentifier>D</SimpleTypeIdentifier></CompositionTypeElement></CompositionType></FunctionType></TypeInitializerClause></TypealiasDecl><TypealiasDecl>
144144
typealias J <TypeInitializerClause>= <AttributedType>inout <Attribute>@autoclosure </Attribute><FunctionType>() -> <SimpleTypeIdentifier>Int</SimpleTypeIdentifier></FunctionType></AttributedType></TypeInitializerClause></TypealiasDecl><TypealiasDecl>
145-
typealias K <TypeInitializerClause>= <FunctionType>(<TupleTypeElement><AttributedType><Attribute>@invalidAttr </Attribute><SimpleTypeIdentifier>Int</SimpleTypeIdentifier></AttributedType>, </TupleTypeElement><TupleTypeElement>inout <SimpleTypeIdentifier>Int</SimpleTypeIdentifier>, </TupleTypeElement><TupleTypeElement><AttributedType>__shared <SimpleTypeIdentifier>Int</SimpleTypeIdentifier></AttributedType>, </TupleTypeElement><TupleTypeElement><AttributedType>__owned <SimpleTypeIdentifier>Int</SimpleTypeIdentifier></AttributedType></TupleTypeElement>) -> <TupleType>()</TupleType></FunctionType></TypeInitializerClause></TypealiasDecl><TypealiasDecl><Attribute>
145+
typealias K <TypeInitializerClause>= <FunctionType>(<TupleTypeElement><AttributedType><Attribute>@invalidAttr </Attribute><SimpleTypeIdentifier>Int</SimpleTypeIdentifier></AttributedType>, </TupleTypeElement><TupleTypeElement><AttributedType>inout <SimpleTypeIdentifier>Int</SimpleTypeIdentifier></AttributedType>, </TupleTypeElement><TupleTypeElement><AttributedType>__shared <SimpleTypeIdentifier>Int</SimpleTypeIdentifier></AttributedType>, </TupleTypeElement><TupleTypeElement><AttributedType>__owned <SimpleTypeIdentifier>Int</SimpleTypeIdentifier></AttributedType></TupleTypeElement>) -> <TupleType>()</TupleType></FunctionType></TypeInitializerClause></TypealiasDecl><TypealiasDecl>
146+
typealias L <TypeInitializerClause>= <FunctionType>(<TupleTypeElement><AttributedType>inout <SimpleTypeIdentifier>Int</SimpleTypeIdentifier></AttributedType></TupleTypeElement>) -> <SimpleTypeIdentifier>Int</SimpleTypeIdentifier></FunctionType></TypeInitializerClause></TypealiasDecl><TypealiasDecl>
147+
typealias M <TypeInitializerClause>= <FunctionType>(<TupleTypeElement>inout arg: <SimpleTypeIdentifier>Int</SimpleTypeIdentifier></TupleTypeElement>) -> <SimpleTypeIdentifier>Int</SimpleTypeIdentifier></FunctionType></TypeInitializerClause></TypealiasDecl><TypealiasDecl>
148+
typealias N <TypeInitializerClause>= <FunctionType>(<TupleTypeElement>inout _ arg: <AttributedType><Attribute>@objc </Attribute><SimpleTypeIdentifier>Int</SimpleTypeIdentifier></AttributedType></TupleTypeElement>) -> <SimpleTypeIdentifier>Int</SimpleTypeIdentifier></FunctionType></TypeInitializerClause></TypealiasDecl><TypealiasDecl><Attribute>
146149

147150
@objc </Attribute><DeclModifier>private </DeclModifier>typealias T<GenericParameterClause><<GenericParameter>a,</GenericParameter><GenericParameter>b</GenericParameter>> </GenericParameterClause><TypeInitializerClause>= <SimpleTypeIdentifier>Int</SimpleTypeIdentifier></TypeInitializerClause></TypealiasDecl><TypealiasDecl><Attribute>
148151
@objc </Attribute><DeclModifier>private </DeclModifier>typealias T<GenericParameterClause><<GenericParameter>a,</GenericParameter><GenericParameter>b</GenericParameter>></GenericParameterClause></TypealiasDecl><ClassDecl>

trunk/test/Syntax/round_trip_parse_gen.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ typealias H = () rethrows -> ()
143143
typealias I = (A & B<C>) -> C & D
144144
typealias J = inout @autoclosure () -> Int
145145
typealias K = (@invalidAttr Int, inout Int, __shared Int, __owned Int) -> ()
146+
typealias L = (inout Int) -> Int
147+
typealias M = (inout arg: Int) -> Int
148+
typealias N = (inout _ arg: @objc Int) -> Int
146149

147150
@objc private typealias T<a,b> = Int
148151
@objc private typealias T<a,b>

0 commit comments

Comments
 (0)