-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Update regex literal delimiters #41430
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,23 @@ | ||
// RUN: %target-typecheck-verify-swift -enable-experimental-string-processing | ||
// REQUIRES: swift_in_compiler | ||
|
||
_ = '/abc/' | ||
_ = #/abc/# | ||
_ = #|abc|# | ||
_ = re'abc' | ||
|
||
_ = ('/[*/', '/+]/', '/.]/') | ||
func foo<T>(_ x: T...) {} | ||
foo(#/abc/#, #|abc|#, re'abc') | ||
|
||
let arr = [#/abc/#, #|abc|#, re'abc'] | ||
|
||
_ = #/\w+/#.self | ||
_ = #|\w+|#.self | ||
_ = re'\w+'.self | ||
|
||
_ = #/#/\/\#\\/# | ||
_ = #|#|\|\#\\|# | ||
_ = re're\r\e\'\\' | ||
|
||
_ = (#/[*/#, #/+]/#, #/.]/#) | ||
// expected-error@-1 {{cannot parse regular expression: quantifier '+' must appear after expression}} | ||
// expected-error@-2 {{cannot parse regular expression: expected ']'}} | ||
|
||
_ = '/\w+/' | ||
_ = '/\'\\/' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
// RUN: %target-typecheck-verify-swift -enable-experimental-string-processing | ||
// REQUIRES: swift_in_compiler | ||
|
||
let s = '/\\/''/ // expected-error {{unterminated regex literal}} | ||
let s = #/\\/''/ // expected-error {{unterminated regex literal}} | ||
_ = #|\| // expected-error {{unterminated regex literal}} | ||
_ = #// // expected-error {{unterminated regex literal}} | ||
_ = re'x // expected-error {{unterminated regex literal}} | ||
|
||
// expected-error@+1 {{unterminated regex literal}} | ||
var unterminated = '/xy | ||
var unterminated = #/xy |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 15 additions & 15 deletions
30
test/StringProcessing/Sema/regex_literal_type_inference.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,48 @@ | ||
// RUN: %target-typecheck-verify-swift -enable-experimental-string-processing | ||
// REQUIRES: swift_in_compiler | ||
|
||
let r0 = '/./' | ||
let r0 = #/./# | ||
let _: Regex<Substring> = r0 | ||
|
||
func takesRegex<Match>(_: Regex<Match>) {} | ||
takesRegex('//') // okay | ||
takesRegex(#//#) // okay | ||
|
||
let r1 = '/.(.)/' | ||
let r1 = #/.(.)/# | ||
// Note: We test its type with a separate statement so that we know the type | ||
// checker inferred the regex's type independently without contextual types. | ||
let _: Regex<(Substring, Substring)>.Type = type(of: r1) | ||
|
||
struct S {} | ||
// expected-error @+2 {{cannot assign value of type 'Regex<(Substring, Substring)>' to type 'Regex<S>'}} | ||
// expected-note @+1 {{arguments to generic parameter 'Match' ('(Substring, Substring)' and 'S') are expected to be equal}} | ||
let r2: Regex<S> = '/.(.)/' | ||
let r2: Regex<S> = #/.(.)/# | ||
|
||
let r3 = '/(.)(.)/' | ||
let r3 = #/(.)(.)/# | ||
let _: Regex<(Substring, Substring, Substring)>.Type = type(of: r3) | ||
|
||
let r4 = '/(?<label>.)(.)/' | ||
let r4 = #/(?<label>.)(.)/# | ||
let _: Regex<(Substring, label: Substring, Substring)>.Type = type(of: r4) | ||
|
||
let r5 = '/(.(.(.)))/' | ||
let r5 = #/(.(.(.)))/# | ||
let _: Regex<(Substring, Substring, Substring, Substring)>.Type = type(of: r5) | ||
|
||
let r6 = '/(?'we'.(?'are'.(?'regex'.)+)?)/' | ||
let _: Regex<(Substring, we: Substring, are: Substring?, regex: [Substring]?)>.Type = type(of: r6) | ||
let r6 = #/(?'we'.(?'are'.(?'regex'.)+)?)/# | ||
let _: Regex<(Substring, we: Substring, are: Substring?, regex: Substring?)>.Type = type(of: r6) | ||
|
||
let r7 = '/(?:(?:(.(.(.)*)?))*?)?/' | ||
let r7 = #/(?:(?:(.(.(.)*)?))*?)?/# | ||
// ^ 1 | ||
// ^ 2 | ||
// ^ 3 | ||
let _: Regex<(Substring, [Substring]?, [Substring?]?, [[Substring]?]?)>.Type = type(of: r7) | ||
let _: Regex<(Substring, Substring??, Substring???, Substring????)>.Type = type(of: r7) | ||
|
||
let r8 = '/well(?<theres_no_single_element_tuple_what_can_we>do)/' | ||
let r8 = #/well(?<theres_no_single_element_tuple_what_can_we>do)/# | ||
let _: Regex<(Substring, theres_no_single_element_tuple_what_can_we: Substring)>.Type = type(of: r8) | ||
|
||
let r9 = '/(a)|(b)|(c)|d/' | ||
let r9 = #/(a)|(b)|(c)|d/# | ||
let _: Regex<(Substring, Substring?, Substring?, Substring?)>.Type = type(of: r9) | ||
|
||
let r10 = '/(a)|b/' | ||
let r10 = #/(a)|b/# | ||
let _: Regex<(Substring, Substring?)>.Type = type(of: r10) | ||
|
||
let r11 = '/()()()()()()()()/' | ||
let r11 = #/()()()()()()()()/# | ||
let _: Regex<(Substring, Substring, Substring, Substring, Substring, Substring, Substring, Substring, Substring)>.Type = type(of: r11) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.