43 Commits

Author SHA1 Message Date
Anthony Latsis
88220a33c3 [NFC] "SwiftVersion" → "LanguageMode" in DiagnosticEngine::warnUntilSwiftVersion, etc. 2025-12-04 15:11:07 +00:00
Slava Pestov
819738c83e AST: Rename mapTypeIntoContext() => mapTypeIntoEnvironment(), mapTypeOutOfContext() => mapTypeOutOfEnvironment() 2025-11-12 14:48:19 -05:00
Becca Royal-Gordon
d1e391094d Improve module selector expr lookup diagnostics 2025-10-24 16:23:49 -07:00
Becca Royal-Gordon
7bf14de2e6 Handle module selectors with local vars right 2025-10-24 16:23:34 -07:00
Becca Royal-Gordon
c58c307c2e Don’t redundantly diagnose key path components
A key path component that resolved to an `ErrorExpr` would be diagnosed twice: once when the `ErrorExpr` was created, then again when it was processed. Fix this redundant diagnostic.
2025-10-20 15:11:14 -07:00
Max Desiatov
b545a28bd3 Add missing // REQUIRES: swift_feature_ForExpressions 2025-10-07 12:34:49 +01:00
Max Desiatov
8cddae2471 Make nested expr work, convert test to executable 2025-10-07 11:16:54 +01:00
Max Desiatov
e7aac5df12 for expressions scaffolding, making constraints work 2025-10-07 11:16:54 +01:00
Allan Shortlidge
8053120624 Sema: Fix a MemberImportVisibility regression in resolveDeclRefExpr().
The changes from https://github.com/swiftlang/swift/pull/84259/ caused a
regression in which declarations from an outer scope could be shadowed
inappropriately by member declarations from a module that has not been
imported. This fix addresses the issue by refactoring `resolveDeclRefExpr()` so
that it performs lookups in two passes. First, it attempts to resolve the decl
ref using the complete lookup algorithm and standard name lookup options, which
will ignore members from modules that haven't been imported if
`MemberImportVisibility` is enabled. Then, if no results were found it re-runs
the full lookup algorithm again with `NameLookupFlags::IgnoreMissingImports`
included to find additional results that ought to be diagnosed as unavailable.
This insures that the unavailable results are not considered until after the
main lookup has already failed.

Resolves rdar://161078015.
2025-10-03 17:33:56 -07:00
Allan Shortlidge
d8fac32dd8 Sema: Fix a crash in migrate mode for MemberImportVisibility.
`TypeChecker::resolveDeclRefExpr()` would leave error nodes in the AST when
performing fallback name lookups with `MemberImportVisibility`. When running in
migration mode for `MemberImportVisibility`, these error nodes would then cause
the compiler to either diagnose a missing error or to crash during SILGen.

Instead of restricting name lookup during `TypeChecker::resolveDeclRefExpr()`,
allow it to find candidates with missing imports and then diagnose them if
necessary before forming a resolve decl ref.

Resolves rdar://154361861.
2025-09-15 20:48:06 -07:00
Meghana Gupta
c764244df0 Merge pull request #84180 from meg-gupta/borrowandmutatepr
Add preliminary support for borrow accessors
2025-09-15 10:01:15 -07:00
Hamish Knight
c84d2abb05 [AST] Allow storing original expression in ErrorTypeRepr
This is useful for ArrowExpr when the sub-expressions aren't valid
TypeExprs. Rather than throwing away the AST, attach it to the
ErrorTypeRepr to ensure we can still type-check it. This ensures
semantic functionality still works correctly, and fixes a crash where
we'd stop visiting an invalid binding pattern, losing track of the
nested VarDecl.
2025-09-11 13:21:03 +01:00
Meghana Gupta
075d44ac43 Sema support for borrow and mutate accessors 2025-09-09 14:41:51 -07:00
Hamish Knight
7e22297b71 [AST] Walk ErrorExpr's original expr in ASTWalker
We set an original expression on ErrorExpr for cases where we have
something semantically invalid that doesn't fit into the AST, but is
still something that the user has explicitly written. For example
this is how we represent unresolved dots without member names (`x.`).
We still want to type-check the underlying expression though since
it can provide useful diagnostics and allows semantic functionality
such as completion and cursor info to work correctly.

rdar://130771574
2025-08-27 15:27:06 +01:00
Nate Cook
85208293c9 Allow inout parameters in expression macros (#82370)
Sema seems to be flagging inout expressions (e.g. &foo) in expression
macros as invalid, setting up a catch 22 where Sema emits an error when
a parameter has the '&' sigil and type checking fails when it doesn't.

This resolves the issue by allowing inout expressions inside macro
expansion expressions.

Resolves https://github.com/swiftlang/swift/issues/82369.
2025-07-03 23:52:16 -07:00
Hamish Knight
b37e34ea8d [Sema] Tighten up function call check in resolveKeyPathExpr
Check for `CallExpr` instead of `ApplyExpr`, we don't support
arbitrary postfix operators in key paths.
2025-06-17 23:07:46 +01:00
Alejandro Alonso
79a51dfcc1 Move resolving param type to CSApply 2025-04-14 15:33:08 -07:00
Alejandro Alonso
ae355007fc Store TypeRepr in TypeValueExpr 2025-04-14 15:33:08 -07:00
Alejandro Alonso
b3f3dd79cf Handle dynamically accessing the static member from type(of:) 2025-04-14 15:32:46 -07:00
Alejandro Alonso
1aaf2c9d29 Allow value generics to show up as static members 2025-04-14 15:32:43 -07:00
Doug Gregor
90a2b3d8a0 Look through "unsafe" expressions when checking for single-value statements
We were rejecting the use of switch expressions on the right-hand side
of an assignment that was marked `unsafe`. Fixes rdar://147944753.
2025-03-27 09:49:34 -07:00
Hamish Knight
e30e5a7539 [Sema] Fix optional chaining behavior with postfix operators
Postfix operators can further be chained within an optional binding
chain, so we need to make sure they're handled in
`getMemberChainSubExpr`. Unresolved member chains still don't allow
them, so we need to add a new `kind` parameter to differentiate the
behavior here.

rdar://147826988
2025-03-26 15:02:42 +00:00
Hamish Knight
fd795d09e4 [Sema] NFC: Factor out PreCheckTarget::wrapMemberChainIfNeeded 2025-03-26 15:02:42 +00:00
Hamish Knight
738c70e8c8 [AST] Always walk folded SequenceExpr if available
Expand the special-cased ASTWalker behavior for folded SequenceExprs
such that we always walk the folded expression when available. This
ensures that we don't attempt to add the same node multiple times
when expanding ASTScopes during pre-checking.

rdar://147751795
2025-03-24 20:18:34 +00:00
Holly Borla
be670da373 Merge pull request #79980 from hborla/closure-body-macro
[Macros] Implement support for function body macros on closures.
2025-03-21 06:19:36 -07:00
Gábor Horváth
ddd36a7cfc Merge pull request #79662 from swiftlang/gaborh/dynamic-self-frt
[cxx-interop] Interpret Self as a static shorthand for FRTs
2025-03-20 17:54:35 +00:00
Amritpan Kaur
86d456e4eb [Sema] Block inout method arguments. 2025-03-19 08:56:03 -07:00
Amritpan Kaur
0c614e09d1 [Expr/AST] Add unresolvedApply component to handle method arguments. 2025-03-19 08:56:03 -07:00
Amritpan Kaur
811d54901b [NFC] Rename unresolvedProperty to unresolvedMember
to generalize for both properties and method members.
2025-03-19 08:53:18 -07:00
Gabor Horvath
b632534528 [cxx-interop] Interpret Self as a static shorthand for FRTs
We do not have dynamic self metadata for foreign reference types.

rdar://145066864
2025-03-19 12:56:56 +00:00
Pavel Yaskevich
42ccd182f6 [PreCheckTarget] Move closure body expansion into PreCheckTarget::walkToClosureExprPre
If closure body is expanded in expression context we need to do
some special handling to make sure that source ranges are not
completely broken.
2025-03-18 20:50:47 -07:00
Alejandro Alonso
15c32e117b Directly store GTPD in TypeValueExpr 2025-02-25 14:11:55 -08:00
Allan Shortlidge
87308e37f1 AST: Avoid creating duplicate AvailabilityScopes under SequenceExprs.
Since availability scopes may be built at arbitrary times, the builder may
encounter ASTs where SequenceExprs still exist and have not been folded, or it
may encounter folded SequenceExprs that have not been removed from the AST.

To avoid a double visit, track whether a SequenceExpr is folded and then
customize how ASTVisitor handles folded sequences.

Resolves rdar://142824799 and https://github.com/swiftlang/swift/issues/78567.
2025-01-17 10:21:22 -08:00
Hamish Knight
0fdb038fc9 Merge pull request #77896 from hamishknight/functionref-split
[AST] Split out "is compound" bit on FunctionRefKind
2024-12-03 09:53:37 +00:00
Hamish Knight
73fb36f371 [AST] Split out "is compound" bit on FunctionRefInfo
FunctionRefKind was originally designed to represent
the handling needed for argument labels on function
references, in which the unapplied and compound cases
are effectively the same. However it has since been
adopted in a bunch of other places where the
spelling of the function reference is entirely
orthogonal to the application level.

Split out the application level from the
"is compound" bit. Should be NFC. I've left some
FIXMEs for non-NFC changes that I'll address in a
follow-up.
2024-12-02 14:11:33 +00:00
Hamish Knight
a4d51419ba [AST] NFC: Rename FunctionRefKind -> FunctionRefInfo 2024-12-02 14:11:32 +00:00
Rintaro Ishizaki
bee4cfe3e5 [PreCheckTarget] Consider UnresolvedSpecializeExpr a chain expression
Optional chain and unresolved member chain should consider
a generic specialization as a chain expression.

rdar://140378864
2024-11-22 12:08:19 -08:00
Rintaro Ishizaki
ffeaa719ef [Sema] Ensure postfix operator is not a part of implicit member chain
But a part of optional chain.
2024-10-12 17:24:08 -07:00
Rintaro Ishizaki
8e8e4d0193 [Parse/Sema] Move OptionalEvaluationExpr wrapping to PreCheckTarget
This simplify the Parser diagnostics and some type checker logic.
2024-10-11 13:12:48 -07:00
Alejandro Alonso
0df42e9841 Lower UDRE to TypeValue if it references a value generic 2024-09-04 15:13:29 -07:00
Hamish Knight
89a3390aa1 [Sema] Move SingleValueStmtUsageChecker into pre-checking
These diagnostics are better suited for pre-checking
since we ought to be emitting them even if there's
some other error with the expression.
2024-08-30 18:55:48 +01:00
Hamish Knight
1139b0e799 Remove shouldWalkCaptureInitializerExpressions from PreCheckTarget
We walk into PatternBindingDecls, so I don't think
there should be any reason we can't walk captures
normally (i.e via their PBD).
2024-08-30 18:55:48 +01:00
Hamish Knight
f0e487dc81 NFC: Rename PreCheckExpression -> PreCheckTarget 2024-08-30 18:55:48 +01:00