Commit Graph

2949 Commits

Author SHA1 Message Date
Doug Gregor 6d41524fe6 [SE-0289] Finish renaming source code, tests to "result builders" 2020-10-20 22:18:51 -07:00
Doug Gregor 0d568a93d4 [SE-0289] Update diagnostics & many other strings to "result builders" 2020-10-20 21:44:09 -07:00
Pavel Yaskevich a0a37d2a71 Merge pull request #34356 from xedin/record-trailing-even-if-types-are-equal
[ConstraintSystem] Record trailing choice match choice when arguments…
2020-10-19 16:20:00 -07:00
swift-ci b654008443 Merge pull request #34337 from nathawes/allow-missing-args-when-type-checking-for-completion 2020-10-19 15:26:50 -07:00
Pavel Yaskevich 340d1e843a [ConstraintSystem] Record trailing choice match choice when arguments/result are equivalent to applied function 2020-10-19 13:55:55 -07:00
Nathan Hawes 15f5222bbd [CodeCompletion][Sema] Allow missing args when solving if the completion location indicates the user may intend to write them later.
func foo(a: Int, b: Int) {}
func foo(a: String) {}

// Int and String should both be valid, despite the missing argument for the
// first overload since the second arg may just have not been written yet.
foo(a: <complete here>

func bar(a: (Int) -> ()) {}
func bar(a: (String, Int) -> ()) {}

// $0 being of type String should be valid, rather than just Int, since $1 may
// just have not been written yet.
bar { $0.<complete here> }
2020-10-19 12:16:19 -07:00
Luciano Almeida 883d583a2f [CSSimplify] Make sure visit and record holes recursivelly for dependent member type 2020-10-16 18:32:20 -03:00
Pavel Yaskevich 461eafff54 [ConstraintSystem] NFC: Move ConstraintSystem.h to include/swift/Sema 2020-10-08 10:45:47 -07:00
Pavel Yaskevich 4954763524 [ConstraintSystem] NFC: Move CSFix.h to include/swift/Sema 2020-10-08 10:43:18 -07:00
Pavel Yaskevich e254f1c3e2 [ConstraintSystem] Infer whether locator is related to return of a single-expression function
This information could be inferred from state recorded in a
constraint system, so to need to record that in the
constraint locator as well.
2020-10-01 11:49:30 -07:00
Pavel Yaskevich 7d6a110210 [CSSimplify] Allow optional object constraint to look through holes
If right-hand side (optional type) has been determined to be a hole,
let's establish that optional object of a hole is a hole and continue
searching for a solution.
2020-09-25 15:00:20 -07:00
Pavel Yaskevich a4701f7d89 [ConstraintSystem] Adjust overload filtering to be less aggressive in code completion mode
Avoid filtering overloads for calls which have code completion
token as an argument, that would always undesired results,
because such calls could be missing arguments before or after
the token.
2020-09-23 17:29:43 -07:00
Pavel Yaskevich c946c803db Merge pull request #34036 from xedin/replace-error-types-with-holes
[CSGen] Avoid failing on invalid declarations
2020-09-23 11:58:32 -07:00
Pavel Yaskevich bdfa8d9099 [AST] Allow hole types to originate from declarations
Associating holes directly with declarations is useful in
cases when declarations are invalid e.g. directly `ErrorType`
or have error types inside.
2020-09-22 15:47:57 -07:00
Robert Widmann ee35a4fe18 Remove NameLookupFlags::KnownPrivate 2020-09-21 10:37:41 -06:00
Robert Widmann 259e1a94c9 Remove UnqualifiedLookupFlags::KnownPrivate 2020-09-21 10:37:41 -06:00
Slava Pestov 0ddd093f5b Sema: Fix unqualified lookup performed for DefineMemberBasedOnUnintendedGenericParam fix
We want to look for protocols at the top level, and not names visible from
the function body. Previously we were passing the function's parent
DeclContext and the source location of the parameter, but this will no
longer work, so pass the SourceFile and an empty source location instead.
2020-09-16 20:07:58 -04:00
Pavel Yaskevich 7b0e46bdfa [ConstraintSystem] Adjust impact of a missing member fix
Currently its impact is set to be less than that of a conversion fix,
which is incorrect. Let's adjust that and increase it even farther for
cases where base is `Any` or `AnyObject`. We couldn't do it for `Any`
before because it was used to represent type holes, but it's no longer
the case.

Resolves: rdar://problem/68155466
2020-09-09 11:24:34 -07:00
Pavel Yaskevich 79a2ab0c8c [ConstraintSystem] Record unable to infer base only if hole originated from affected reference
If base type of a unresolved member reference couldn't be determined
(represented as a hole type), before recording a fix about lack of
contextual information, let's make sure that hole originated in either
base or result type of this reference, otherwise the problem is
contextual e.g. generic parameter, which supposed to act as contextual
type for a reference, couldn't be inferred.
2020-09-07 11:44:51 -07:00
Pavel Yaskevich e4f6041dba [ConstraintSystem] Record generic fix if destination of a pointer conversion is invalid
If the right-hand side (destination) of value-to-pointer conversion
is incorrect e.g. base type of member is a hole, let's record
a generic "invalid conversion" failure.

Resolves: rdar://problem/68254165
2020-09-04 13:30:53 -07:00
Holly Borla 3fd882cadf [NFC] Rename "storage wrapper var" to "projection var" or "projected value"
in property wrapper-related code.
2020-09-02 18:07:40 -07:00
Rintaro Ishizaki c48a676a1c Merge pull request #31679 from Jumhyn/implicit-member-chains-different-types
[SE-0287] [Sema] Implementation for implicit member chains
2020-08-28 10:47:53 -07:00
Pavel Yaskevich a6c3e6f543 Merge pull request #33658 from xedin/introduce-hole-type
[ConstraintSystem] Introduce a new type to represent a type hole
2020-08-28 10:40:15 -07:00
Frederick Kellison-Linn 352adc3b5d Remove Argument from UnresolvedMemberExpr
Instead, an expresison like `.foo()` is represented as an `UnresolvedMemberExpr` nested inside a `CallExpr`.
2020-08-26 22:42:30 -04:00
Frederick Kellison-Linn 7b05352cf1 [Sema] Improve invalid lvalue diagnostics for UnresolvedMemberExpr
We previously were not properly handling the diagnostics for using an rvalue implicit member on the left hand side of an assignment. This adds the proper handling and extends it for member chains.
2020-08-26 22:42:30 -04:00
Frederick Kellison-Linn 74d004057e [Sema] Remove unnecessary impact adjustment 2020-08-26 22:42:30 -04:00
Frederick Kellison-Linn 4e9b7b20db [Sema] Inject implicit ParenExpr for unresolved member chains
In order to give unresolved member chain result types visibility in the AST, we inject an implicit ParenExpr in CSGen that lives only for the duration of type checking, and gets removed during solution application.
2020-08-26 22:42:29 -04:00
Frederick Kellison-Linn aedde34fec [Sema] Move unresolved base tracking into CSGen
Remove the tracking of unresolved base types from the constraint system, and place it entirely within the generation phase. We have other ways of getting at the base types after generation.
2020-08-26 22:42:29 -04:00
Frederick Kellison-Linn 3b5deab114 More diagnostic improvements 2020-08-26 22:42:29 -04:00
Frederick Kellison-Linn 1069fe280f Fixup diagnostics 2020-08-26 22:42:29 -04:00
Frederick Kellison-Linn 5b5e30b6d7 Implement implicit member chains 2020-08-26 22:42:29 -04:00
Pavel Yaskevich d039107bdb [ConstraintSystem] Replace use of UnresolvedType with specialized HoleType 2020-08-26 18:43:10 -07:00
Pavel Yaskevich 78ea3de8e4 [AST] Introduce a new type to represent a type hole in constraint system
Instead of using `UnresolvedType` as a placeholder for a type hole,
let's switch over to a dedicated "rich" `HoleType` which is capable
of storing "originator" type - type variable or dependent member
type which couldn't be resolved.

This makes it easier for the solver to determine origins of
a hole which helps to diagnose certain problems better. It also
helps code completion to locate "expected type" of the context
even when it couldn't be completely resolved.
2020-08-26 16:55:39 -07:00
Hamish Knight dd9e1cf618 [CS] Don't use TMF_GenerateConstraints in simplifyConstraint
Adding a new unsolved constraint is redundant, as
it's already present in the inactive list. Noticed
by inspection.
2020-08-25 10:16:43 -07:00
Pavel Yaskevich 3ad8ea86bb [CSFix] Add a fix to ignore function builder body which fails pre-check
Fix is anchored on a `BraceStmt` associated with an invalid closure.
It's diagnosing the problem by calling `ConstraintSystem::preCheckExpression`
for all expressions in the body without suppressing errors.
2020-08-17 12:39:29 -07:00
Luciano Almeida b1eccb594d [Sema] Do not diagnose contextual type mismatches for malformed key path expressions (#33230)
* [AST] Adding hasSingleInvalidComponent to key path expression

* [Sema] Adding a new fix and failure to diagnose missing key path component

* [Sema] Recording new fix for key path missing components and remove diagnose from pre-check

* [tests] Adjusting key path missing component contextual tests

* [Sema] Renaming missing component key path fix and failure

* [Sema] Correcting comments typos
2020-08-16 12:27:21 -03:00
Holly Borla 89c499ec61 [ConstraintSystem] Remove default argument for updateWorkList from
ConstraintSystem::mergeEquivalenceClasses.

Most callers don't use the default, and it's important to consider
the value of this argument for each call to mergeEquivalenceClasses.
2020-08-11 09:35:45 -07:00
Pavel Yaskevich c6bc6f0bdc Merge pull request #33363 from Jumhyn/SR-13357
[Sema] Allow inference of binding to differing lvalue-ness type var…
2020-08-08 21:03:01 -07:00
Frederick Kellison-Linn eb625f7b2a [Sema] Allow inference of binding to type var of differing lvalue-ness…
when we have an optional type. This uncovered an error with unresolved member lookup where we allowed an unresolved value member constraint to fail if lookup failed in an optional type wrapping a type variable.

This resolves SR-13357.
2020-08-08 08:53:16 -04:00
Pavel Yaskevich 08771ab5e9 Merge pull request #33364 from xedin/trailing-closure-warning
[Diagnostics] Extract backward scan deprecation warning into a fix/diagnostic
2020-08-07 15:20:33 -07:00
Pavel Yaskevich 44d686f71d [ConstraintSystem] Use new "specify label" fix/diagnostic to warn about backward scan 2020-08-07 11:50:29 -07:00
Holly Borla 9e818233f0 Merge pull request #33296 from hborla/merge-joined-literal-typevars
[ConstraintSystem] Add a type variable merging heuristic to addJoinConstraint
2020-08-07 09:07:19 -07:00
Holly Borla cd44ca87a9 [ConstraintSystem] Move getAtomicLiteralKind to TypeVariableType::Implementation 2020-08-06 07:36:46 -07:00
Holly Borla 43aafcdb8e [CSGen] Use addJoinConstraint for joining array literal element types. 2020-08-06 07:36:46 -07:00
Holly Borla 0efb86a7fb [ConstraintSystem] Add an overload of addJoinConstraint that takes in
an iterator range and a callback to get the type.

This allows callers to lazily compute the input types to join rather
than constructing an array first. The old addJoinConstraint is now
a wrapper for this new overload.
2020-08-06 07:36:46 -07:00
Nathan Hawes ef6c374516 [Sema/Index] Resolve #keyPath components so they can be indexed
Unlike \keypath expressions, only the property components of #keypath
expressions were being resolved, so index wouldn't pick up references for their
qualifying types.

Also fixes a code completion bug where it was reporting members from the Swift
rather than ObjC side of bridged types.

Resolves rdar://problem/61573935
2020-08-05 15:27:52 -07:00
Pavel Yaskevich 8e4688009d Merge pull request #33298 from xedin/rdar-65413640
[Diagnostics] Detect and diagnose type mismatches related to function…
2020-08-04 19:37:20 -07:00
Pavel Yaskevich 98007904b8 [Diagnostics] Detect and diagnose type mismatches related to function builder result
Generic requirement failures are already covered but general type
mismatches have to be handled separately.

Resolves: rdar://problem/65413640
2020-08-04 14:52:18 -07:00
Rintaro Ishizaki 00e4a76ef0 Revert "[Sema/Index] Resolve #keyPath components so they get handled by indexing, semantic highlighting, etc." 2020-08-04 12:51:52 -07:00
Pavel Yaskevich 9b33ffa828 Merge pull request #33272 from xedin/rdar-65254452
[Diagnostics] Do more checking before recording `force downcast` fix
2020-08-04 10:22:47 -07:00