Commit Graph

1609 Commits

Author SHA1 Message Date
Nathan Hawes
edbbefce91 [CodeCompletion][Sema] Add fix to treat empty or single-element array literals as dictionaries when used as such
In the single-element case, it is treated as the dictionary key.

func takesDict(_ x: [Int: String]) {}
takesDict([]) // diagnose with fixit to add missing ':'
takesDict([1]) // diagnose with fixit to add missing ': <#value#>'
takesDict([foo.<complete>]) // prioritise Int members in completion results -
                            // the user just hasn't written the value yet.

The above previously failed with a generic mismatch error in normal type
checking (due to the literal being parsed as an array literal) and code
completion could not pick up the expected type from the context.
2020-11-11 11:48:39 -08:00
Pavel Yaskevich
d7c6c00e04 Merge pull request #34614 from xedin/improvements-to-ambiguity-diags
[Diagnostic] Improve diagnostics for situations with ambiguity caused by conformance requirements
2020-11-09 16:07:11 -08:00
Pavel Yaskevich
66fbdce2f8 [ConstraintSystem] Don't increase a score for conditional requirement failures
Let's consider conditional requirement failure to mean that parent
conformance requirement wasn't satisfied and nothing more, that helps
to disambiguate certain situations and avoid filtering out conditional
failures.

Resolves: rdar://problem/64844584
2020-11-06 12:06:00 -08:00
Pavel Yaskevich
1f1400581f Merge pull request #34584 from xedin/rdar-70880670
[CSGen] Turn invalid decls into holes
2020-11-05 12:09:06 -08:00
Pavel Yaskevich
f1fd528a1b [CSFix] Add a fix to detect/diagnose references to invalid declarations
Upon attempt to generate constraints for invalid declaration reference
let's turn that into a hole and record this new fix to diagnose it
once solution has been reached.
2020-11-03 17:52:40 -08:00
Pavel Yaskevich
fa5c7120ef [ConstraintSystem] Ignore value-to-optional conversions to correctly detect conformance failures
If there is a conformance failure related to existential conversion
let's ignore that fact that there could be an implicit value-to-optional
conversion involved, because it's not the main issue in cases like
that.

Resolves: rdar://problem/70814576
2020-11-03 15:51:55 -08:00
Alejandro Alonso
424802fb34 Revert SE-0283 (#34492)
Reverted despite build failures.
2020-10-29 17:32:06 -07:00
Pavel Yaskevich
92fe04f31f Merge pull request #34432 from xedin/remove-rvalue-adjument
[ConstraintSystem] Remove `RValueAdjustment` locator element
2020-10-26 12:08:09 -07:00
Pavel Yaskevich
1683fb91b6 [ConstraintSystem] Remove RValueAdjustment locator element
It was used for unresolved member and `.dynamicType` references
as well as a couple of other places, but now unresolved member
references no longer need that due to new implicit "chain result"
AST node and other places could use more precise locators
e.g. new `.dynamicType` locator or `sequence element` for `for in`
loops.
2020-10-26 00:40:45 -07:00
Azoy
f21a306ae5 [AST] Introduce BuiltinProtocolConformance 2020-10-22 18:24:27 -04:00
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