Commit Graph

22 Commits

Author SHA1 Message Date
Hamish Knight
6a435960b7 Requestify regex pattern parsing
Instead of doing the pattern parsing in both the
C++ parser and ASTGen, factor out the parsing into
a request that returns the pattern to emit, regex
type, and version. This can then be lazily run
during type-checking.
2024-10-11 19:25:58 +01:00
Hamish Knight
7971056e21 [Sema] Fold SequenceExpr in pre-checking pre-walk
Doing it in the post-walk meant we ended up
walking the children twice, which lead to duplicate
diagnostics and incorrect inference of the
level of application for function references. Move
it to the pre-walk, ensuring that we resolve any
operator references before folding.
2024-07-29 00:07:45 +01:00
Rintaro Ishizaki
0e122544ca [CodeCompletion] Fix completion for 'catch' pattern bound values
Previously code completion for 'catch' pattern bound values didn't work
correctly because code completion type checker fails to type check the
value decl in the pattern.
That was because the body of the 'do' statement is not type checked, so
the thrown error is not determined, then falled backed to the default
'Never', which doesn't matches any patterns.
To resolve this, always type check the body when typechecking 'catch'
patterns. Also, pretends 'do {}' throws 'any Error' even without
any throwing expressions in the body.

rdar://126699879
2024-04-22 11:09:12 -07:00
Doug Gregor
ea836389f7 Suppress warnings about Never error types in catch clauses
Enabling typed throws has introduced some spurious warnings about error
values of `Never` type on top of the custom "unreachable" diagnostics
for catch clauses, so suppress the new warnings---they aren't helpful.
2024-01-04 09:37:35 -08:00
Rintaro Ishizaki
47f18d492e [ASTGen] Move regex literal parsing from SwiftCompilerSources to ASTGen
ASTGen always builds with the host Swift compiler, without requiring
bootstrapping, and is enabled in more places. Move the regex literal
parsing logic there so it is enabled in more host environments, and
makes use of CMake's Swift support. Enable all of the regex literal
tests when ASTGen is built, to ensure everything is working.

Remove the "AST" and "Parse" Swift modules from SwiftCompilerSources,
because they are no longer needed.
2023-11-16 10:59:23 -08:00
Pavel Yaskevich
58ffca8f74 [ConstraintSystem] Don't produce partially matching note if none of the overloads matched 2023-05-09 14:11:38 -07:00
Hamish Knight
68075696eb [CS] A couple of minor improvements to operator diagnostics
- Simplify the fix locator when looking for a
fix already present in a pattern match, this
avoids us emitting both a diagnostic for the
argument conversion, and for a conformance failure.
- Include tuples in the diagnostic logic where
we emit a generic "operator cannot be applied"
diagnostic, as a conformance diagnostic is
unlikely to be helpful in that case.
2023-05-04 14:53:57 +01:00
Pavel Yaskevich
bb1da5e599 [CSFix] Diagnose extraneous force unwraps in ambiguous context 2023-02-24 23:48:03 -08:00
Doug Gregor
1b14b5d356 Fixup some test cases 2023-01-02 21:22:05 -08:00
Alex Hoppen
e14fa7291f [CS] Don’t fail constraint generation for ErrorExpr or if type fails to resolve
Instead of failing constraint generation by returning `nullptr` for an `ErrorExpr` or returning a null type when a type fails to be resolved, return a fresh type variable. This allows the constraint solver to continue further and produce more meaningful diagnostics.

Most importantly, it allows us to produce a solution where previously constraint generation for a syntactic element had failed, which is required to type check multi-statement closures in result builders inside the constraint system.
2022-07-20 09:46:12 +02:00
Stephen Canon
9afbddf2c3 Remove use of ~= in bare-slash-regex tests. 2022-06-30 15:23:37 -04:00
Hamish Knight
8d59eb08df [Parse] Ban trailing space for /.../ regex literals
Ban space and tab as the last character of a
`/.../` regex literal, unless escaped with a
backslash. This matches the banning of space and
tab as the first character, and helps avoid breaking
source in even more cases.
2022-06-23 20:38:28 +01:00
Hamish Knight
350a01aeb0 [Parse] Expand unbalanced ) regex literal heuristic
Previously we would only check for a starting
character of `)` when performing a tentative
lex of a regex literal. Expand this to cover the
entire range of the regex literal, ensuring to
take escapes and custom character classes into
account.
2022-05-12 11:49:11 +01:00
Hamish Knight
9c62319be1 [Parse] Lenient prefix / parsing
Treat a prefix operator containing `/` the same as
the unapplied infix operator case, where we
tentatively lex. This means that we bail if there
is no closing `/` or the starting character is
invalid. This leaves binary operator containing
`/` in expression position as the last place where
we know that we definitely have a regex literal.
2022-05-12 11:49:10 +01:00
Hamish Knight
105ab3149a [Parse] Re-allow prefix operators containing / 2022-05-12 11:49:09 +01:00
Hamish Knight
ba28b6a19b [Parse] Split prefix operators from regex in the lexer
Teach the lexer not to consider `/` an operator
character when attempting to re-lex a regex
literal. This allows us to split off a prefix
operator.

Previously this was done after-the-fact in the
parser, but that didn't cover the unapplied infix
operator case, and didn't form a `tok::amp_prefix`
for `foo(&/.../)`, which led to a suboptimal
diagnostic.

This also now means we'll split an operator for
cases such as `foo(!/^/)` rather than treating it
as an unapplied infix operator.

rdar://92469917
2022-04-29 10:53:56 +01:00
Hamish Knight
f9a6a8b7e7 [test] Add some additional /.../ tests 2022-04-29 10:53:56 +01:00
Hamish Knight
5c3f6db997 [test] Update for new string processing changes
We now define a `~=` operator for `Regex`.
2022-04-28 18:45:52 +01:00
Rintaro Ishizaki
d292a95296 [SwiftCompiler/Regex] Use bridged DiagnosticEngine for error reporting
This fixes:
 * An issue where the diagnostic messages were leaked
 * Diagnose at correct position inside the regex literal

To do this:
 * Introduce 'Parse' SwiftCompiler module that is a bridging layer
   between '_CompilerRegexParser' and C++ libParse
 * Move libswiftParseRegexLiteral and libswiftLexRegexLiteral to 'Parse'

Also this change makes 'SwiftCompilerSources/Package.swift' be configured
by CMake so it can actually be built with 'swift-build'.

rdar://92187284
2022-04-22 22:53:46 -07:00
Richard Wei
72ebcded98 Integrate newer string processing (a0ed7e1)
Friend PR: apple/swift-experimental-string-processing#282.

Also remove the `-enable-experimental-pairwise-build-block` flag when building regex modules as the feature is already on by default.
2022-04-15 12:01:45 -07:00
Hamish Knight
f1a799037e [Parse] Introduce /.../ regex literals
Start parsing regex literals with `/.../`
delimiters.

rdar://83253726
2022-04-12 16:03:49 +01:00
Hamish Knight
5a8dff0a76 [Parse] Emit error on prefix operator containing /
When forward slash regex is enabled, start emitting
an error on prefix operators containing the
`/` character.
2022-04-12 16:03:48 +01:00