Skip to content

Commit 06c1fe7

Browse files
author
John Holdsworth
committed
Move back to single quoted syntax
1 parent 3f97af7 commit 06c1fe7

File tree

9 files changed

+27
-22
lines changed

9 files changed

+27
-22
lines changed

lib/Parse/Lexer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1911,7 +1911,8 @@ void Lexer::lexStringLiteral(unsigned CustomDelimiterLen) {
19111911
wasErroneous |= CharValue == ~1U;
19121912
}
19131913

1914-
if (QuoteChar == '\'') {
1914+
if (QuoteChar == '\'' && !(CurPtr - TokStart == 3 &&
1915+
!IsMultilineString && CustomDelimiterLen == 0 )) {
19151916
assert(!IsMultilineString && CustomDelimiterLen == 0 &&
19161917
"Single quoted string cannot have custom delimiter, nor multiline");
19171918
diagnoseSingleQuoteStringLiteral(TokStart, CurPtr);

lib/Parse/ParseDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ void Parser::parseTopLevelItems(SmallVectorImpl<ASTNode> &items) {
235235
}
236236
}
237237

238-
#if SWIFT_BUILD_SWIFT_SYNTAX
238+
#if SWIFT_BUILD_SWIFT_SYNTAX && 0
239239
if (existingParsingTransaction)
240240
existingParsingTransaction->abort();
241241

lib/Sema/TypeChecker.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ ProtocolDecl *TypeChecker::getLiteralProtocol(ASTContext &Context, Expr *expr) {
103103
if (const auto *SLE = dyn_cast<StringLiteralExpr>(expr)) {
104104
if (SLE->isSingleUnicodeScalar())
105105
return TypeChecker::getProtocol(
106-
Context, expr->getLoc(), SLE->getValue().size() == 1 ?
106+
Context, expr->getLoc(), SLE->getValue().size() == 1 &&
107+
SLE->getValue().data()[-1] == '\'' ?
107108
KnownProtocolKind::ExpressibleByASCIIScalarLiteral :
108109
KnownProtocolKind::ExpressibleByUnicodeScalarLiteral);
109110

test/Constraints/patterns.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,9 @@ func testExprPatternIsolation() {
631631
}
632632
for case 0 in nil {} // expected-error {{'nil' requires a contextual type}}
633633
for case 0 in [nil] {}
634-
// expected-error@-1 {{expression pattern of type 'Int' cannot match values of type 'Any?'}}
634+
// expected-error@-1 {{type 'Any' cannot conform to 'Equatable'}}
635+
// expected-note@-2 {{only concrete types such as structs, enums and classes can conform to protocols}}
636+
// expected-note@-3 {{requirement from conditional conformance of 'Any?' to 'Equatable'}}
635637

636638
// Though we will try Double for an integer literal...
637639
let d: Double = 0
@@ -677,7 +679,7 @@ func testExprPatternIsolation() {
677679

678680
// FIXME: Bad error (https://github.com/apple/swift/issues/64279)
679681
if case .e(nil, 0) = produceMultiPayload() {}
680-
// expected-error@-1 {{expression pattern of type 'Unicode.Scalar' cannot match values of type 'UInt8'}}
682+
// expected-error@-1 {{expression pattern of type 'String' cannot match values of type 'Substring'}}
681683
// expected-note@-2 {{overloads for '~=' exist with these partially matching parameter lists}}
682684

683685
if case .e(5, nil) = produceMultiPayload() as MultiPayload<Int?> {}

test/Constraints/rdar105782480.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ func foo(value: MyEnum) {
1111
takeClosure {
1212
switch value {
1313
case .second(let drag).invalid:
14-
// expected-error@-1 {{expression pattern of type 'Unicode.Scalar' cannot match values of type 'MyEnum'}}
15-
// expected-error@-2 {{type 'Unicode.Scalar' has no member 'second'}}
14+
// expected-error@-1 {{value of type 'MyEnum' has no member 'invalid'}}
15+
// expected-error@-2 {{'let' binding pattern cannot appear in an expression}}
1616
break
1717
}
1818
}

test/Misc/character_ops.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@
44
let c = UInt8(ascii: "a")
55

66
// CHECK: OK
7-
if c == "a" {
7+
if c == 'a' {
88
print("OK")
99
}
1010

1111
// CHECK: OK
12-
if c != "b" {
12+
if c != 'b' {
1313
print("OK")
1414
}
1515

1616
// CHECK: OK
1717
switch c {
18-
case "a":
18+
case 'a':
1919
print("OK")
20-
case "b":
20+
case 'b':
2121
fallthrough
2222
default:
2323
print("FAIL")
@@ -26,27 +26,27 @@ default:
2626
let d: UInt8? = UInt8(ascii: "a")
2727

2828
// CHECK: OK
29-
if d == "a" {
29+
if d == 'a' {
3030
print("OK")
3131
}
3232

3333
// CHECK: OK
34-
if d != "b" {
34+
if d != 'b' {
3535
print("OK")
3636
}
3737

3838
// CHECK: OK
3939
switch d {
40-
case "a":
40+
case 'a':
4141
print("OK")
42-
case "b":
42+
case 'b':
4343
fallthrough
4444
default:
4545
print("FAIL")
4646
}
4747

4848
// CHECK: OK
49-
if UInt8(unicode: "a") == "a" {
49+
if UInt8(unicode: "a") == 'a' {
5050
print("OK")
5151
}
5252

test/Parse/new_parser_diagnostics.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@
44
// RUN: %target-typecheck-verify-swift -enable-experimental-feature ParserDiagnostics
55

66
_ = [(Int) -> async throws Int]()
7-
// expected-error@-1{{'async throws' must precede '->'}}
8-
// expected-note@-2{{move 'async throws' in front of '->'}}{{15-21=}} {{21-28=}} {{20-21= }} {{12-12=async }} {{12-12=throws }}
7+
// expected-error@-1{{'async' may only occur before '->'}}
8+
// expected-error@-2{{'async throws' must precede '->'}}
9+
// expected-error@-3{{'throws' may only occur before '->'}}{{21-28=}} {{12-12=throws }}
10+
// expected-note@-4{{move 'async throws' in front of '->'}}

test/expr/expressions.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,6 @@ func testSingleQuoteStringLiterals() {
516516
_ = "abc\('def')" // expected-error{{single-quoted string literal found, use '"'}}{{13-18="def"}}
517517
_ = 'ab\("c")' // expected-error{{single-quoted string literal found, use '"'}}{{7-17="ab\\("c")"}}
518518
_ = 'a\('b')c' // expected-error{{single-quoted string literal found, use '"'}}{{7-17="a\\('b')c"}}
519-
// expected-error@-1{{single-quoted string literal found, use '"'}}{{11-14="b"}}
520519

521520
_ = "abc' // expected-error{{unterminated string literal}}
522521
_ = 'abc" // expected-error{{unterminated string literal}}

test/stdlib/UnicodeScalarDiagnostics.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ func test_UnicodeScalarDoesNotImplementArithmetic(_ us: UnicodeScalar, i: Int) {
99
var a1 = "a" + "b" // OK
1010
isString(&a1)
1111
// We don't check for the overload choices list on the overload note match because they may change on different platforms.
12-
let a2 = "a" - "b"
13-
let a3 = "a" * "b"
14-
let a4 = "a" / "b"
12+
let a2 = "a" - "b" // expected-error {{binary operator '-' cannot be applied to two 'String' operands}}
13+
let a3 = "a" * "b" // expected-error {{binary operator '*' cannot be applied to two 'String' operands}}
14+
let a4 = "a" / "b" // expected-error {{binary operator '/' cannot be applied to two 'String' operands}}
1515

1616
let b1 = us + us // expected-error {{binary operator '+' cannot be applied to two 'UnicodeScalar' (aka 'Unicode.Scalar') operands}}
1717
let b2 = us - us // expected-error {{binary operator '-' cannot be applied to two 'UnicodeScalar' (aka 'Unicode.Scalar') operands}}

0 commit comments

Comments
 (0)