Commit Graph

932 Commits

Author SHA1 Message Date
Alex Hoppen
1e05bd858e Merge pull request #62833 from ahoppen/ahoppen/allow-closure-with-error
[Sema] Don’t fail constraint generation if a closure contains an ErrorExpr
2023-01-31 21:17:27 +01:00
Alex Hoppen
17d47bb691 [Sema] Don’t fail constraint generation if a closure contains an ErrorExpr
It appears like this was missed in #60062.
2023-01-30 17:36:36 +01:00
Anthony Latsis
792a9cf7c0 [DiagnosticsQoI] Sema: Use 'underlying' instead of 'concrete' in opaque result type diagnostic 2023-01-28 20:51:40 +03:00
Luciano Almeida
f441e271a8 Merge pull request #62924 from LucianoPAlmeida/opaque-diags
[Diagnostics] Improving diagnostics for inference of opaque result concrete type
2023-01-18 08:38:26 -03:00
Luciano Almeida
e513d23c0b [Sema] Improving global actor function mismatch diagnostic 2023-01-13 20:47:23 -03:00
Luciano Almeida
c6ea1f6611 [Diagnostics] Improving diagnostics for inference of opaque result concrete type 2023-01-09 09:41:54 -03:00
Holly Borla
c363fa2510 [Diagnostics] Make same-shape requirement failure diagnostics less sensitive
to binding order.
2023-01-07 09:50:14 -08:00
Anthony Latsis
1bb407ac8c [NFC] AST: Rename ComponentIdentTypeReprIdentTypeRepr 2023-01-07 07:15:36 +03:00
Doug Gregor
71ca9c86e6 [Macros] Diagnose when we forget to provide macro arguments.
Unlike functions, you can't curry macros; diagnose when one omits the
arguments in a macro expansion of a macro that has a parameter list.
2023-01-02 21:22:04 -08:00
Doug Gregor
806b5a8777 [Macros] Diagnose errors where a macro is used without the '#'. 2023-01-02 21:22:04 -08:00
Doug Gregor
af49a90dde Customize diagnostic text for extra/missing/mislabeled arguments for callee kind
Most of the diagnostics for extra/missing/mislabeled arguments refer
to argument to a "call". Some (but not call) would substitute in
"subscript". None would refer to an argument to a macro expansion
properly.

Rework all of these to refer to the argument in a call, subscript, or
macro expansion as appropriate. Fix up lots of tests that now say
"subscript" instead, and add tests for macro expansions.
2023-01-02 21:22:04 -08:00
Doug Gregor
bdc01ea985 [Macros] Handle macro argument lists in diagnostics
This improves diagnostics for missing/extra/incorrectly-labeled arguments.
2023-01-02 21:22:04 -08:00
Holly Borla
e966b4ef7d [CSDiagnostics] Add an error message for pack expansion expressions over
packs that don't have the same shape.
2022-12-21 08:25:10 -05:00
Erik Eckstein
ab1b343dad use new llvm::Optional API
`getValue` -> `value`
`getValueOr` -> `value_or`
`hasValue` -> `has_value`
`map` -> `transform`

The old API will be deprecated in the rebranch.
To avoid merge conflicts, use the new API already in the main branch.

rdar://102362022
2022-11-21 19:44:24 +01:00
Pavel Yaskevich
3c0401c7cb [CSDiagnostics] NFC: Prioritize sequence element over other contextual element diagnostics 2022-10-31 12:21:45 -07:00
Pavel Yaskevich
c0e09cb0dc [CSDiagnostics] Simplify MissingContextualConformanceFailure and avoid storing diagnostic
Carrying diagnostic through the method is becoming unmanagable and
prune to issues due to "in-flight" diagnostic replacement.
2022-10-31 12:21:45 -07:00
Pavel Yaskevich
8ab37ca449 [Diagnostics] Diagnose type with mismatching generic arguments in ternary expr
Fixes a missing diagnostic related to types with mismatched
generic arguments in one of both ternary branches.

Resolves: rdar://98862079
2022-10-27 15:56:50 -07:00
Holly Borla
67fb143f0e [AST] Remove ReifyPackExpr. 2022-10-10 16:25:26 -07:00
Pavel Yaskevich
1a79d93121 Merge pull request #40702 from calda/cal--implicit-weak-self
[SE-0365] Allow implicit self for `weak self` captures
2022-09-30 10:30:57 -07:00
Anthony Latsis
18156d1177 Merge pull request #61347 from AnthonyLatsis/migrate-compiler-to-gh-issues
Gardening: Migrate compiler sources to GitHub issues
2022-09-30 10:48:52 +03:00
Anthony Latsis
2843e0c871 Gardening: Migrate compiler sources to GitHub issues 2022-09-29 23:58:55 +03:00
Hamish Knight
bca941b152 [AST] NFC: Rename IfExpr -> TernaryExpr
This matches what we call it in SwiftSyntax, and
is just generally clearer.
2022-09-28 10:33:31 +01:00
Cal Stephens
5946c66962 Style updates 2022-09-23 07:09:52 -07:00
Cal Stephens
84896edaf2 Use Ctx.Id_self and update comments 2022-09-15 20:01:40 -07:00
Hamish Knight
4716f61fba [AST] Introduce explicit actions for ASTWalker
Replace the use of bool and pointer returns for
`walkToXXXPre`/`walkToXXXPost`, and instead use
explicit actions such as `Action::Continue(E)`,
`Action::SkipChildren(E)`, and `Action::Stop()`.
There are also conditional variants, e.g
`Action::SkipChildrenIf`, `Action::VisitChildrenIf`,
and `Action::StopIf`.

There is still more work that can be done here, in
particular:

- SourceEntityWalker still needs to be migrated.
- Some uses of `return false` in pre-visitation
methods can likely now be replaced by
`Action::Stop`.
- We still use bool and pointer returns internally
within the ASTWalker traversal, which could likely
be improved.

But I'm leaving those as future work for now as
this patch is already large enough.
2022-09-13 10:35:29 +01:00
Hamish Knight
6804623a82 Fix some nullptr dereferences
Turns out we were getting away with dereferencing
`nullptr` in a few cases as `walk` would use
`nullptr` to indicate that the walk should be
stopped, and luckily Clang didn't optimize it to
something broken.

This commit is fairly defensive and sprinkles
some null checks for calls to `walk` directly
on a body of a function or top-level code decl.
2022-09-13 10:35:28 +01:00
Cal Stephens
9167a177cc Merge branch 'main' into cal--implicit-weak-self 2022-09-11 10:24:55 -07:00
Holly Borla
34d962461f Merge pull request #60671 from hborla/invalid-existential-access
[Diagnostics] Improve diagnostics for invalid type access on existential types.
2022-08-22 19:39:50 -04:00
Holly Borla
ddb5c13ef5 [Diagnostics] Improve the diagnostics for invalid type access on an
existential type in expression context.
2022-08-19 22:22:43 -04:00
Holly Borla
268f6e25d1 [Diagnostics] Improve the diagnostics for invalid associatedtype or
typealias access on existential types by mentioning the base type in
the error message.
2022-08-19 22:22:43 -04:00
Pavel Yaskevich
3ebc541fd5 [CSDiagnostics] Verify that member is in collection context
`MissingMemberFailure::diagnoseInLiteralCollectionContext`
should verify that a parent (or parent of a parent) expression
is indeed a collection expression instead of checking types.

Resolves: rdar://91452726
2022-08-17 12:12:27 -07:00
Pavel Yaskevich
a803cb50fa Merge pull request #60384 from xedin/rdar-94506352-aux-vars
[CSClosure] Add support for projected/wrapper values
2022-08-05 09:19:08 -07:00
Pavel Yaskevich
5ee5a22cf1 [TypeChecker] NFC: Add a dedicated method to get outermost attached wrapper
The outermost wrapper is the one at index `0` in the wrapper list
but it's easy for humans to make a reverse assumption since outermost
is the back of the list. Let's add a dedicated method to reduce error
probability of the property wrapper APIs.
2022-08-04 17:30:02 -07:00
Suyash Srijan
b2593ee5e3 [CSDiagnostics] Optional closure diagnostic improvement (#60321)
* [NFC] Add a getOptionalityDepth method to return the number of optionals a type has

* [NFC] Use getOptionalityDepth to remove existing code

* [AST] Add a new diagnostic note for suggesting optional chaining

* [CSDiagnostics] Tweak MissingOptionalUnwrapFailure to suggest using optional chaining on closure

* [Test] Add a couple of test cases for perform_optional_chain_on_closure

* [CSDiagnostics] Change DeclRefExpr casts to isa checks

* [AST] Update diagnostic phrasing

* [Sema] Use new diagnostic identifier and update comment

* [Test] Add a new test case for function type

* [Test] Update cfuncs_parse.swift tests to check for new diagnostic note
2022-08-04 21:40:17 +01:00
Pavel Yaskevich
a59b8bee14 [Diagnostics] Detect that return type mismatch belongs to a result builder
Since result builders are now type-checked like regular closures
diagnostics have to detect that contextual result type mismatch
occured in `return` statement associated with result builder transformed
function/closure.
2022-08-02 11:59:03 -07:00
Pavel Yaskevich
0202785b33 [ResultBuilder] Diagnostics: Don't diagnose unsupported statement if it is a brace
Brace statement are marked unsuported only if there is no appropriate overload
of `buildBlock` and that is diagnosed inline.
2022-08-02 11:59:03 -07:00
Pavel Yaskevich
568174cc19 [CSDiagnostics] Don't try to diagnose empty case/switch statements as unsupported
Such statements are already incorrect and going to be diagnosed by the parser.
2022-08-02 11:59:03 -07:00
Hamish Knight
5418e8d934 [AST] Remove ArgumentList::composeTupleOrParenType
Remove a redundant bit of diagnostic logic now
that we better diagnose cases where an uncallable
variable is in an overload set for a mismatched
apply. Tweak another bit of diagnostic logic to
only apply to a single arg/param case, as that
seems to be what it's meant for.
2022-07-26 12:51:54 +01:00
Hamish Knight
13fe88cc57 [AST] Rename isCallableNominalType -> isCallAsFunctionType
Make it explicit that we're checking for
`callAsFunction` instead of `dynamicallyCall`.
2022-07-25 22:03:55 +01:00
zoecarver
ca5fa9aa9b [nfc] Clang format changes. 2022-07-18 17:15:15 -04:00
zoecarver
9d1d03124b [nfc][cxx-interop] Add diagnostics when something cannot be imported. 2022-07-18 17:15:15 -04:00
Cal Stephens
778a2fc1f5 Merge branch 'main' into cal--implicit-weak-self 2022-07-18 10:00:23 -07:00
Doug Gregor
c564698625 [Constraint solver] Improve modeling of fix behavior.
Rather than re-using `DiagnosticBehavior` to describe how a fix should
act, introduce `FixBehavior` to cover the differences between (e.g.)
always-as-awarning and downgrade-to-warning. While here, split the
`isWarning` predicate into two different predicates:

* `canApplySolution`: Whether we can still apply a solution when it
contains this particular fix.
* `affectsSolutionScore`: Whether

These two predicates are currently tied together, because that's the
existing behavior, but we don't necessarily want them to stay that way.
2022-07-07 12:17:11 -07:00
Doug Gregor
218a3f79e0 [Constraint solver] Downgrade/ignore concurrency issues more generally.
Instead of the `warning` Boolean threaded through the solver's
diagnostics, thread `DiagnosticBehavior` to be used as the behavior
limit. Use this for concurrency checking (specifically dropped
`@Sendable` and dropped global actors) so the solver gets more control
over these diagnostics.

This change restores the diagnostics to a usable state after the prior
change, which introduced extra noise. The only change from existing
beavior is that dropping a global actor from a function type is now
always a warning in Swift < 6. This is partly intentional, because
there are some places where dropping the global actor is well-formed.
2022-07-01 11:45:44 -07:00
Doug Gregor
248b72bbff Track the pre-adjusted "reference" type for declaration reference. 2022-06-30 17:00:32 -07:00
Doug Gregor
1063e8126e [Constraint system] Track the original opened type for a selected overload. 2022-06-30 17:00:31 -07:00
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
Holly Borla
0053526c5d Merge pull request #41909 from hborla/existential-any-anyobject
[Sema] Use `ExistentialType` for `Any` and `AnyObject`.
2022-06-24 20:51:50 -07:00
Anthony Latsis
d76e74391f Merge pull request #59526 from AnthonyLatsis/closure_result_mismatch_diagQoI
Sema, DiagQoI: Fix and tailor diagnosis of explicit closure result type conflicts
2022-06-21 00:19:52 +03:00
Anthony Latsis
a07f2b4889 Sema, DiagQoI: Fix and tailor diagnosis of explicit closure result type conflicts 2022-06-20 22:20:32 +03:00