Files
swift-mirror/test/StringProcessing/Sema/regex_builder_already_imported.swift
Hamish Knight c56ea461b6 [Sema] Add fix-it to import RegexBuilder
For code such as the following:

```
let r = Regex {
  /abc/
}
```

If RegexBuilder has not been imported, emit a
specialized diagnostic and fix-it to add
`import RegexBuilder` to the file.

Unfortunately we're currently prevented from
emitting the specialized diagnostic in cases where
the builder contains references to RegexBuilder
types, such as:

```
let r = Regex {
  Capture {
    /abc/
  }
}
```

This is due to the fact that we bail from CSGen
due to the reference to `Capture` being turned
into an `ErrorExpr`. We ought to be able to
handle solving in the presence of such errors, but
for now I'm leaving it as future work.

rdar://93176036
2022-06-28 11:38:41 +01:00

17 lines
585 B
Swift

// RUN: %target-typecheck-verify-swift -enable-bare-slash-regex -disable-availability-checking
import RegexBuilder
extension Regex where Output == Substring {
init(_ x: String) {} // expected-note {{'init(_:)' declared here}}
}
func foo() {
// FIXME: This diagnostic could probably be better, it's not clear we should
// be resolving to init(_ x: String) vs the result builder API and diagnosing
// the fact that Int isn't a RegexComponent.
_ = Regex { // expected-error {{trailing closure passed to parameter of type 'String' that does not accept a closure}}
0
}
}