Skip to content

Commit 7fd4406

Browse files
authored
Merge pull request #38915 from hamishknight/refactor-evaluate-print-loop
[test] Use %refactor-check-compiles in more places
2 parents 671e8d7 + f58c62c commit 7fd4406

13 files changed

+1617
-1517
lines changed

include/swift/Basic/LangOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ namespace swift {
149149
/// Should potential unavailability on enum cases be downgraded to a warning?
150150
bool WarnOnPotentiallyUnavailableEnumCase = false;
151151

152+
/// Should the editor placeholder error be downgraded to a warning?
153+
bool WarnOnEditorPlaceholder = false;
154+
152155
/// Maximum number of typo corrections we are allowed to perform.
153156
/// This is disabled by default until we can get typo-correction working within acceptable performance bounds.
154157
unsigned TypoCorrectionLimit = 0;

include/swift/Option/FrontendOptions.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,10 @@ def warn_on_potentially_unavailable_enum_case : Flag<["-"],
462462
"warn-on-potentially-unavailable-enum-case">,
463463
HelpText<"Downgrade potential unavailability of enum case to a warning">;
464464

465+
def warn_on_editor_placeholder : Flag<["-"],
466+
"warn-on-editor-placeholder">,
467+
HelpText<"Downgrade the editor placeholder error to a warning">;
468+
465469
def report_errors_to_debugger : Flag<["-"], "report-errors-to-debugger">,
466470
HelpText<"Deprecated, will be removed in future versions.">;
467471

lib/Frontend/CompilerInvocation.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,8 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
467467

468468
Opts.WarnOnPotentiallyUnavailableEnumCase |=
469469
Args.hasArg(OPT_warn_on_potentially_unavailable_enum_case);
470+
Opts.WarnOnEditorPlaceholder |= Args.hasArg(OPT_warn_on_editor_placeholder);
471+
470472
if (auto A = Args.getLastArg(OPT_enable_access_control,
471473
OPT_disable_access_control)) {
472474
Opts.EnableAccessControl

lib/Parse/Lexer.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2145,9 +2145,10 @@ void Lexer::tryLexEditorPlaceholder() {
21452145
if (Ptr[0] == '<' && Ptr[1] == '#')
21462146
break;
21472147
if (Ptr[0] == '#' && Ptr[1] == '>') {
2148-
// Found it. Flag it as error (or warning, if in playground mode) for the
2149-
// rest of the compiler pipeline and lex it as an identifier.
2150-
if (LangOpts.Playground) {
2148+
// Found it. Flag it as error (or warning, if in playground mode or we've
2149+
// been asked to warn) for the rest of the compiler pipeline and lex it
2150+
// as an identifier.
2151+
if (LangOpts.Playground || LangOpts.WarnOnEditorPlaceholder) {
21512152
diagnose(TokStart, diag::lex_editor_placeholder_in_playground);
21522153
} else {
21532154
diagnose(TokStart, diag::lex_editor_placeholder);

test/refactoring/ConvertAsync/basic.swift

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ typealias NestedAliasCallback = SomeCallback
1414
// 1. Check various functions for having/not having async alternatives
1515

1616
// RUN: %refactor-check-compiles -add-async-alternative -dump-text -source-filename %s -pos=%(line+4):1 | %FileCheck -check-prefix=ASYNC-SIMPLE %s
17-
// RUN: %refactor -add-async-alternative -dump-text -source-filename %s -pos=%(line+3):6 | %FileCheck -check-prefix=ASYNC-SIMPLE %s
18-
// RUN: %refactor -add-async-alternative -dump-text -source-filename %s -pos=%(line+2):12 | %FileCheck -check-prefix=ASYNC-SIMPLE %s
19-
// RUN: %refactor -add-async-alternative -dump-text -source-filename %s -pos=%(line+1):20 | %FileCheck -check-prefix=ASYNC-SIMPLE %s
17+
// RUN: %refactor-check-compiles -add-async-alternative -dump-text -source-filename %s -pos=%(line+3):6 | %FileCheck -check-prefix=ASYNC-SIMPLE %s
18+
// RUN: %refactor-check-compiles -add-async-alternative -dump-text -source-filename %s -pos=%(line+2):12 | %FileCheck -check-prefix=ASYNC-SIMPLE %s
19+
// RUN: %refactor-check-compiles -add-async-alternative -dump-text -source-filename %s -pos=%(line+1):20 | %FileCheck -check-prefix=ASYNC-SIMPLE %s
2020
func simple(/*cs*/ completion: @escaping (String) -> Void /*ce*/) { }
2121
// ASYNC-SIMPLE: basic.swift [[# @LINE-1]]:1 -> [[# @LINE-1]]:1
2222
// ASYNC-SIMPLE-NEXT: @available(*, renamed: "simple()")
@@ -113,7 +113,7 @@ func errorOnly(completion: @escaping (Error?) -> Void) { }
113113
// ASYNC-ERRORONLY-NEXT: }
114114
// ASYNC-ERRORONLY: func errorOnly() async throws { }
115115

116-
// RUN: %refactor -add-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=ASYNC-ERRORNONOPTIONALRESULT %s
116+
// RUN: %refactor-check-compiles -add-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=ASYNC-ERRORNONOPTIONALRESULT %s
117117
func errorNonOptionalResult(completion: @escaping (String, Error?) -> Void) { }
118118
// ASYNC-ERRORNONOPTIONALRESULT: {
119119
// ASYNC-ERRORNONOPTIONALRESULT-NEXT: Task {
@@ -253,7 +253,7 @@ func mixed(_ completion: @escaping (String?, Int) -> Void) { }
253253
// MIXED-NEXT: }
254254
// MIXED: func mixed() async -> (String?, Int) { }
255255

256-
// RUN: %refactor -add-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=MIXED-OPTIONAL-ERROR %s
256+
// RUN: %refactor-check-compiles -add-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=MIXED-OPTIONAL-ERROR %s
257257
func mixedOptionalError(_ completion: @escaping (String?, Int, Error?) -> Void) { }
258258
// MIXED-OPTIONAL-ERROR: {
259259
// MIXED-OPTIONAL-ERROR-NEXT: Task {
@@ -377,7 +377,7 @@ protocol MyProtocol {
377377
}
378378

379379
// RUN: not %refactor -add-async-alternative -dump-text -source-filename %s -pos=%(line+2):1
380-
// RUN: %refactor -convert-to-async -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=NON-COMPLETION %s
380+
// RUN: %refactor-check-compiles -convert-to-async -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=NON-COMPLETION %s
381381
func nonCompletion(a: Int) { }
382382
// NON-COMPLETION: func nonCompletion(a: Int) async { }
383383

@@ -387,27 +387,27 @@ func nonEscapingCompletion(completion: (Int) -> Void) { }
387387
// NON-ESCAPING-COMPLETION: func nonEscapingCompletion(completion: (Int) -> Void) async { }
388388

389389
// RUN: not %refactor -add-async-alternative -dump-text -source-filename %s -pos=%(line+2):1
390-
// RUN: %refactor -convert-to-async -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=MULTIPLE-RESULTS %s
390+
// RUN: %refactor-check-compiles -convert-to-async -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=MULTIPLE-RESULTS %s
391391
func multipleResults(completion: @escaping (Result<String, Error>, Result<String, Error>) -> Void) { }
392392
// MULTIPLE-RESULTS: func multipleResults(completion: @escaping (Result<String, Error>, Result<String, Error>) -> Void) async { }
393393

394394
// RUN: not %refactor -add-async-alternative -dump-text -source-filename %s -pos=%(line+2):1
395-
// RUN: %refactor -convert-to-async -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=NON-VOID %s
395+
// RUN: %refactor-check-compiles -convert-to-async -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=NON-VOID %s
396396
func nonVoid(completion: @escaping (String) -> Void) -> Int { return 0 }
397397
// NON-VOID: func nonVoid(completion: @escaping (String) -> Void) async -> Int { return 0 }
398398

399399
// RUN: not %refactor -add-async-alternative -dump-text -source-filename %s -pos=%(line+2):1
400-
// RUN: %refactor -convert-to-async -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=COMPLETION-NON-VOID %s
400+
// RUN: %refactor-check-compiles -convert-to-async -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=COMPLETION-NON-VOID %s
401401
func completionNonVoid(completion: @escaping (String) -> Int) -> Void { }
402402
// COMPLETION-NON-VOID: func completionNonVoid(completion: @escaping (String) -> Int) async -> Void { }
403403

404404
// RUN: not %refactor -add-async-alternative -dump-text -source-filename %s -pos=%(line+2):1
405-
// RUN: %refactor -convert-to-async -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=ALREADY-THROWS %s
405+
// RUN: %refactor-check-compiles -convert-to-async -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=ALREADY-THROWS %s
406406
func alreadyThrows(completion: @escaping (String) -> Void) throws { }
407407
// ALREADY-THROWS: func alreadyThrows(completion: @escaping (String) -> Void) async throws { }
408408

409409
// RUN: not %refactor -add-async-alternative -dump-text -source-filename %s -pos=%(line+2):1
410-
// RUN: %refactor -convert-to-async -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=AUTO-CLOSURE %s
410+
// RUN: %refactor-check-compiles -convert-to-async -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=AUTO-CLOSURE %s
411411
func noParamAutoclosure(completion: @escaping @autoclosure () -> Void) { }
412412
// AUTO-CLOSURE: func noParamAutoclosure(completion: @escaping @autoclosure () -> Void) async { }
413413

@@ -640,13 +640,17 @@ func testSkipAssign() {
640640
// SKIP-ASSIGN-FUNC-NEXT: print("assigned"){{$}}
641641
// SKIP-ASSIGN-FUNC-NEXT: }{{$}}
642642

643+
// Same as noParamAutoclosure defined above, but used just for the test below.
644+
// This avoids a compiler error when converting noParamAutoclosure to async.
645+
func noParamAutoclosure2(completion: @escaping @autoclosure () -> Void) {}
646+
643647
// RUN: %refactor -convert-to-async -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefixes=SKIP-AUTOCLOSURE-FUNC %s
644648
func testSkipAutoclosure() {
645649
// RUN: not %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):3
646-
noParamAutoclosure(completion: print("autoclosure"))
650+
noParamAutoclosure2(completion: print("autoclosure"))
647651
}
648652
// SKIP-AUTOCLOSURE-FUNC: {{^}}func testSkipAutoclosure() async {
649-
// SKIP-AUTOCLOSURE-FUNC: noParamAutoclosure(completion: print("autoclosure")){{$}}
653+
// SKIP-AUTOCLOSURE-FUNC: noParamAutoclosure2(completion: print("autoclosure")){{$}}
650654

651655
// RUN: %refactor -convert-to-async -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=EMPTY-CAPTURE %s
652656
func testEmptyCapture() {

0 commit comments

Comments
 (0)