mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Parse: __shared and __owned should be contextual keywords
This was a source compatibility regression, someone actually had an identifier named __shared.
This commit is contained in:
@@ -787,7 +787,10 @@ public:
|
|||||||
bool parseTypeAttributeList(VarDecl::Specifier &Specifier,
|
bool parseTypeAttributeList(VarDecl::Specifier &Specifier,
|
||||||
SourceLoc &SpecifierLoc,
|
SourceLoc &SpecifierLoc,
|
||||||
TypeAttributes &Attributes) {
|
TypeAttributes &Attributes) {
|
||||||
if (Tok.isAny(tok::at_sign, tok::kw_inout, tok::kw___shared, tok::kw___owned))
|
if (Tok.isAny(tok::at_sign, tok::kw_inout) ||
|
||||||
|
(Tok.is(tok::identifier) &&
|
||||||
|
(Tok.getRawText().equals("__shared") ||
|
||||||
|
Tok.getRawText().equals("__owned"))))
|
||||||
return parseTypeAttributeListPresent(Specifier, SpecifierLoc, Attributes);
|
return parseTypeAttributeListPresent(Specifier, SpecifierLoc, Attributes);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -179,13 +179,17 @@ public:
|
|||||||
/// used
|
/// used
|
||||||
bool canBeArgumentLabel() const {
|
bool canBeArgumentLabel() const {
|
||||||
// Identifiers, escaped identifiers, and '_' can be argument labels.
|
// Identifiers, escaped identifiers, and '_' can be argument labels.
|
||||||
if (is(tok::identifier) || isEscapedIdentifier() || is(tok::kw__))
|
if (is(tok::identifier) || isEscapedIdentifier() || is(tok::kw__)) {
|
||||||
return true;
|
// ... except for '__shared' and '__owned'.
|
||||||
|
if (getRawText().equals("__shared") ||
|
||||||
|
getRawText().equals("__owned"))
|
||||||
|
return false;
|
||||||
|
|
||||||
// 'let', 'var', 'inout', '__shared', and '__owned'
|
return true;
|
||||||
// cannot be argument labels.
|
}
|
||||||
if (isAny(tok::kw_let, tok::kw_var, tok::kw_inout,
|
|
||||||
tok::kw___owned, tok::kw___shared))
|
// 'let', 'var', and 'inout' cannot be argument labels.
|
||||||
|
if (isAny(tok::kw_let, tok::kw_var, tok::kw_inout))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// All other keywords can be argument labels.
|
// All other keywords can be argument labels.
|
||||||
|
|||||||
@@ -140,8 +140,6 @@ DECL_KEYWORD(struct)
|
|||||||
DECL_KEYWORD(subscript)
|
DECL_KEYWORD(subscript)
|
||||||
DECL_KEYWORD(typealias)
|
DECL_KEYWORD(typealias)
|
||||||
DECL_KEYWORD(var)
|
DECL_KEYWORD(var)
|
||||||
DECL_KEYWORD(__shared)
|
|
||||||
DECL_KEYWORD(__owned)
|
|
||||||
|
|
||||||
DECL_KEYWORD(fileprivate)
|
DECL_KEYWORD(fileprivate)
|
||||||
DECL_KEYWORD(internal)
|
DECL_KEYWORD(internal)
|
||||||
|
|||||||
@@ -1820,19 +1820,22 @@ bool Parser::parseTypeAttributeListPresent(VarDecl::Specifier &Specifier,
|
|||||||
SourceLoc &SpecifierLoc,
|
SourceLoc &SpecifierLoc,
|
||||||
TypeAttributes &Attributes) {
|
TypeAttributes &Attributes) {
|
||||||
Specifier = VarDecl::Specifier::Owned;
|
Specifier = VarDecl::Specifier::Owned;
|
||||||
while (Tok.isAny(tok::kw_inout, tok::kw___shared, tok::kw___owned)) {
|
while (Tok.is(tok::kw_inout) ||
|
||||||
|
(Tok.is(tok::identifier) &&
|
||||||
|
(Tok.getRawText().equals("__shared") ||
|
||||||
|
Tok.getRawText().equals("__owned")))) {
|
||||||
if (SpecifierLoc.isValid()) {
|
if (SpecifierLoc.isValid()) {
|
||||||
diagnose(Tok, diag::parameter_specifier_repeated)
|
diagnose(Tok, diag::parameter_specifier_repeated)
|
||||||
.fixItRemove(SpecifierLoc);
|
.fixItRemove(SpecifierLoc);
|
||||||
} else {
|
} else {
|
||||||
if (Tok.is(tok::kw___owned)) {
|
if (Tok.is(tok::kw_inout)) {
|
||||||
Specifier = VarDecl::Specifier::Owned;
|
|
||||||
} else if (Tok.is(tok::kw_inout)) {
|
|
||||||
Specifier = VarDecl::Specifier::InOut;
|
Specifier = VarDecl::Specifier::InOut;
|
||||||
} else if (Tok.is(tok::kw___shared)) {
|
} else if (Tok.is(tok::identifier)) {
|
||||||
Specifier = VarDecl::Specifier::Shared;
|
if (Tok.getRawText().equals("__shared")) {
|
||||||
} else {
|
Specifier = VarDecl::Specifier::Shared;
|
||||||
llvm_unreachable("unhandled specifier kind?");
|
} else if (Tok.getRawText().equals("__owned")) {
|
||||||
|
Specifier = VarDecl::Specifier::Owned;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SpecifierLoc = consumeToken();
|
SpecifierLoc = consumeToken();
|
||||||
|
|||||||
@@ -182,15 +182,18 @@ Parser::parseParameterClause(SourceLoc &leftParenLoc,
|
|||||||
|
|
||||||
// ('inout' | 'let' | 'var' | '__shared' | '__owned')?
|
// ('inout' | 'let' | 'var' | '__shared' | '__owned')?
|
||||||
bool hasSpecifier = false;
|
bool hasSpecifier = false;
|
||||||
while (Tok.isAny(tok::kw_inout, tok::kw_let, tok::kw_var,
|
while (Tok.isAny(tok::kw_inout, tok::kw_let, tok::kw_var) ||
|
||||||
tok::kw___shared, tok::kw___owned)) {
|
(Tok.is(tok::identifier) &&
|
||||||
|
(Tok.getRawText().equals("__shared") ||
|
||||||
|
Tok.getRawText().equals("__owned")))) {
|
||||||
if (!hasSpecifier) {
|
if (!hasSpecifier) {
|
||||||
if (Tok.is(tok::kw_inout)) {
|
if (Tok.is(tok::kw_inout)) {
|
||||||
// This case is handled later when mapping to ParamDecls for
|
// This case is handled later when mapping to ParamDecls for
|
||||||
// better fixits.
|
// better fixits.
|
||||||
param.SpecifierKind = VarDecl::Specifier::InOut;
|
param.SpecifierKind = VarDecl::Specifier::InOut;
|
||||||
param.SpecifierLoc = consumeToken();
|
param.SpecifierLoc = consumeToken();
|
||||||
} else if (Tok.is(tok::kw___shared)) {
|
} else if (Tok.is(tok::identifier) &&
|
||||||
|
Tok.getRawText().equals("__shared")) {
|
||||||
// This case is handled later when mapping to ParamDecls for
|
// This case is handled later when mapping to ParamDecls for
|
||||||
// better fixits.
|
// better fixits.
|
||||||
param.SpecifierKind = VarDecl::Specifier::Shared;
|
param.SpecifierKind = VarDecl::Specifier::Shared;
|
||||||
|
|||||||
@@ -175,13 +175,16 @@ ParserResult<TypeRepr> Parser::parseTypeSimple(Diag<> MessageID,
|
|||||||
if (Tok.is(tok::kw_inout)) {
|
if (Tok.is(tok::kw_inout)) {
|
||||||
SpecifierLoc = consumeToken();
|
SpecifierLoc = consumeToken();
|
||||||
TypeSpecifier = VarDecl::Specifier::InOut;
|
TypeSpecifier = VarDecl::Specifier::InOut;
|
||||||
} else if (Tok.is(tok::kw___shared)) {
|
} else if (Tok.is(tok::identifier)) {
|
||||||
SpecifierLoc = consumeToken();
|
if (Tok.getRawText().equals("__shared")) {
|
||||||
TypeSpecifier = VarDecl::Specifier::Shared;
|
assert(false);
|
||||||
} else if (Tok.is(tok::kw___owned)) {
|
SpecifierLoc = consumeToken();
|
||||||
SpecifierLoc = consumeToken();
|
TypeSpecifier = VarDecl::Specifier::Shared;
|
||||||
TypeSpecifier = VarDecl::Specifier::Owned;
|
} else if (Tok.getRawText().equals("__owned")) {
|
||||||
|
assert(false);
|
||||||
|
SpecifierLoc = consumeToken();
|
||||||
|
TypeSpecifier = VarDecl::Specifier::Owned;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (Tok.getKind()) {
|
switch (Tok.getKind()) {
|
||||||
|
|||||||
10
test/Compatibility/shared_owned_identifiers.swift
Normal file
10
test/Compatibility/shared_owned_identifiers.swift
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
// RUN: %target-swift-frontend -typecheck %s
|
||||||
|
|
||||||
|
func __shared() {}
|
||||||
|
|
||||||
|
func __owned() {}
|
||||||
|
|
||||||
|
func foo() {
|
||||||
|
__shared()
|
||||||
|
__owned()
|
||||||
|
}
|
||||||
@@ -1,23 +1,5 @@
|
|||||||
{
|
{
|
||||||
key.results: [
|
key.results: [
|
||||||
{
|
|
||||||
key.kind: source.lang.swift.keyword,
|
|
||||||
key.name: "__owned",
|
|
||||||
key.sourcetext: "__owned",
|
|
||||||
key.description: "__owned",
|
|
||||||
key.typename: "",
|
|
||||||
key.context: source.codecompletion.context.none,
|
|
||||||
key.num_bytes_to_erase: 0
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key.kind: source.lang.swift.keyword,
|
|
||||||
key.name: "__shared",
|
|
||||||
key.sourcetext: "__shared",
|
|
||||||
key.description: "__shared",
|
|
||||||
key.typename: "",
|
|
||||||
key.context: source.codecompletion.context.none,
|
|
||||||
key.num_bytes_to_erase: 0
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
key.kind: source.lang.swift.keyword,
|
key.kind: source.lang.swift.keyword,
|
||||||
key.name: "associatedtype",
|
key.name: "associatedtype",
|
||||||
|
|||||||
Reference in New Issue
Block a user