Commit Graph

1245 Commits

Author SHA1 Message Date
zoecarver
38658a051f [cxx-interop] Fix test for linux; bail if we didn't load the overlay. 2023-02-21 10:52:57 -08:00
Luciano Almeida
22a18de1b1 [Sema] Improving integer literal as boolean diagnostic 2023-02-21 10:30:48 -03:00
zoecarver
1b0ee8e8de [cxx-interop] Fix two source locations; replace end with nil. 2023-02-20 14:57:51 -08:00
zoecarver
d19b587c35 [cxx-interop] Update based on review feedback. 2023-02-20 14:57:50 -08:00
zoecarver
5ac94a8a90 [cxx-interop] Completely overhaul diagnostics/notes for unsafe projections. 2023-02-20 14:57:50 -08:00
zoecarver
4e0860b0d2 [cxx-interp] Add fix-its for front(), back(), begin(), and end(). 2023-02-20 14:57:50 -08:00
zoecarver
9ce9310df5 [cxx-interop] Offer fix-it to re-write ".at(42)" as "[42]".
Only applies to random access collections. The first of many fix-its like this :)
2023-02-20 14:57:50 -08:00
Hamish Knight
c87b1b8bef Merge pull request #63022 from hamishknight/express-yourself 2023-02-03 16:40:09 +00:00
Kavon Farvardin
ab130883a3 Initial ban of move-only types from being used generically
Since values of generic type are currently assumed to always
support copying, we need to prevent move-only types from
being substituted for generic type parameters.

This approach leans on a `_Copyable` marker protocol to which
all generic type parameters implicitly must conform.

A few other changes in this initial implementation:

- Now every concrete type that can conform to Copyable will do so. This fixes issues with conforming to a protocol that requires Copyable.
- Narrowly ban writing a concrete type `[T]` when `T` is move-only.
2023-02-01 23:38:28 -08:00
Holly Borla
e41cdfbdd4 Merge pull request #63341 from hborla/generalize-macro-expansion-expr
[Macros] Generalize `MacroExpansionExpr` and use it for both freestanding and attached macros.
2023-02-01 11:04:39 -08:00
Hamish Knight
a40f1abaff Introduce if/switch expressions
Introduce SingleValueStmtExpr, which allows the
embedding of a statement in an expression context.
This then allows us to parse and type-check `if`
and `switch` statements as expressions, gated
behind the `IfSwitchExpression` experimental
feature for now. In the future,
SingleValueStmtExpr could also be used for e.g
`do` expressions.

For now, only single expression branches are
supported for producing a value from an
`if`/`switch` expression, and each branch is
type-checked independently. A multi-statement
branch may only appear if it ends with a `throw`,
and it may not `break`, `continue`, or `return`.

The placement of `if`/`switch` expressions is also
currently limited by a syntactic use diagnostic.
Currently they're only allowed in bindings,
assignments, throws, and returns. But this could
be lifted in the future if desired.
2023-02-01 15:30:18 +00:00
Holly Borla
9b5cf1d2ff [Diagnostics] Remove the MacroMissingArguments constraint fix and its
associated failure diagnostic.

This constraint fix is unused now that MacroExpansionExpr always has an
argument list, and goes through the AddMissingArguments constraint fix for
this error.
2023-01-31 17:45:31 -08:00
Holly Borla
26786c1e09 [Macros] Make macro expansions always have an argument list. If an explicit
argument list isn't written, an implicit, empty list is created.
2023-01-31 17:04:35 -08:00
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