Commit Graph

689 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
409aa35312 [Diagnostic] Add a diagnostic for invalid declaration refs
If AST node is a reference to an invalid declaration let's
diagnose it as such unless some errors have been emitted
(invalid declaration itself should have a diagnostic
describing a reason why it's invalid).
2020-11-04 12:15:45 -08:00
Pavel Yaskevich
9384813b49 [Diagnostics] Split "only concrete types conform to protocols" into a separate note 2020-10-27 14:52:23 -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
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
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
Pavel Yaskevich
461eafff54 [ConstraintSystem] NFC: Move ConstraintSystem.h to include/swift/Sema 2020-10-08 10:45:47 -07:00
Luciano Almeida
6ceda75414 [CSDiagnostic] Minor code improvement on MissingGenericArgumentsFailure addressing fixme 2020-10-04 16:19:06 -03:00
Pavel Yaskevich
4d0ab13c36 Merge pull request #34089 from xedin/nil-as-a-hole
[Diagnostics] Diagnose cases when it's impossible to infer type for `nil` literal
2020-09-28 12:13:25 -07:00
Slava Pestov
2fb3c7c975 Merge pull request #34092 from slavapestov/didset-access-semantics-cycle
Sema: Simplify adjustSelfTypeForMember() a little bit to avoid a cycle
2020-09-26 10:15:52 -04:00
Slava Pestov
d5febdb791 Sema: Fix diagnoseSelfAssignment() with computed properties
This check did not handle MemberRefExprs with an InOutExpr base,
giving it inconsistent behavior:

- With a class, we would diagnose self-assignment of computed
  properties

- With a struct, accesses to computed properties would build a
  MemberRefExpr with an InOutExpr base, so self-assignments
  were *not* diagnosed.

Let's tweak the check to consistently diagnose self-assignments
to stored properties only, instead of the emergent behavior
as described above.
2020-09-26 00:02:42 -04:00
Pavel Yaskevich
f96d6d3486 [Diagnostics] Remove obsolete special case for _ = nil 2020-09-25 15:56:18 -07:00
Pavel Yaskevich
1fb69a7d43 [Diagnostics] Diagnose cases when it's impossible to infer type for nil
Detect and diagnose situations when it's invalid to use `nil`
literal without more context e.g. `_ = nil`, `nil as? Int`, or
`_ = nil!`.
2020-09-25 14:59:54 -07:00
Slava Pestov
dcafd585c1 Sema: Use ASTScope::lookupSingleLocalDecl() in MissingOptionalUnwrapFailure 2020-09-25 17:59:20 -04:00
Slava Pestov
29ce77209c AST: Convert ConstructorDecl::getDelegatingOrChainedInitKind() into a request
This method had a messy contract:

- Setting the diags parameter to nullptr inhibited caching

- The initExpr out parameter could only used if no result
  had yet been cached

Let's instead use the request evaluator here.
2020-09-25 17:59:20 -04:00
Doug Gregor
1c5be70255 Merge pull request #33995 from DougGregor/conformance-checker-missing-witnesses
[Conformance checker] Capture potential matches for missing witnesses.
2020-09-18 20:31:35 -07:00
Doug Gregor
f91767cfa0 [Conformance checker] Capture potential matches for missing witnesses.
Rework the data structures we use in the conformance checker to talk
about missing witnesses, so they can capture the set of potential
matches. This will allow us to delay more diagnostics to later,
more uniformly.
2020-09-18 16:50:22 -07:00
Doug Gregor
3b8656dc6f [Function builders] Add stubs for missing buildBlock and buildLimitedAvailability
The lack of these functions in a function builder is diagnosed in
different places in the type checker. Extend these diagnostics to
provide stubs in the function builder.

Thanks to Suyash for the suggestion!
2020-09-16 16:31:03 -07:00
Doug Gregor
20ab640e56 [Function builders] Add code completion for build* functions.
When performing code completion inside the declaration of a type with
the function builder attribute, also include completions for all of
the possible "build" functions.
2020-09-16 11:55:09 -07:00
Doug Gregor
19cfe21db8 [Function builders] Add Fix-Its for missing build* members in builders.
When a use of a function builder involves a statement kind that the
function builder doesn't support (e.g., if-else), add a note to the
diagnostic that specifies what methods need to be added to the
function builder to support that statement, including Fix-Its with
stub implementations.
2020-09-15 22:32:21 -07:00
Suyash Srijan
49e7c6126c [Diagnostics] Diagnose comparisons with '.nan' and suggest using '.isNan' instead (#33860)
* [AST] Add 'FloatingPoint' known protocol kind

* [Sema] Emit a diagnostic for comparisons with '.nan' instead of using '.isNan'

* [Sema] Update '.nan' comparison diagnostic wording

* [Sema] Explicitly check for either arguments to be '.nan' and tweak a comment

* [Test] Tweak some comments

* [Diagnostic] Change 'isNan' to 'isNaN'

* [Sema] Fix a bug where firstArg was checked twice for FloatingPoint conformance and update some comments

* [Test] Fix comments in test file

* [NFC] Add a new 'isStandardComparisonOperator' method to 'Identifier' and use it in ConstraintSystem

* [NFC] Reuse argument decl extraction code and switch over to the new 'isStandardComparisonOperator' method

* [NFC] Update conformsToKnownProtocol to accept DeclContext and use it to check for FloatingPoint conformance
2020-09-09 22:08:42 +01:00
Holly Borla
3332df6f89 Merge pull request #33777 from hborla/rename-storage-wrapper
[NFC][Property Wrappers] Rename "storage wrapper var" to "projection var/projected value"
2020-09-03 18:29:04 -07:00
Luciano Almeida
ccdbb0ed6a Merge pull request #33772 from LucianoPAlmeida/correcting-source-location-keypath-fix
[CSDiagnostics] Ensure fix-it inserts uses correct location in infered key path root optional unwrapped
2020-09-03 17:31:39 -03: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
Luciano Almeida
ed7e03b21b [CSDiagnostics] Ensure fix-it inserts uses correct location in infered key path root optional unwrapped 2020-09-02 19:27:05 -03:00
Luciano Almeida
8bbffacb28 Merge pull request #33708 from LucianoPAlmeida/minor-typo
[NFC] Correcting minor typo on a CSDiagnostics comment
2020-08-30 23:53:33 -03:00
Luciano Almeida
88e26c019f [NFC] Correcting minor typo on a CSDiagnostics comment 2020-08-30 21:21:51 -03: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
Luciano Almeida
4b921c3487 [Sema] Improve diagnostics for key path root type inferred as option accessing wrapped member 2020-08-27 20:07:18 -03:00
Pavel Yaskevich
4847ec9a6b [AST/TypeChecker] Add more asserts to make sure types don't get into AST 2020-08-27 13:18:45 -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
5de23f5cfc [Sema] Rebase and address feedback for implicit member chains 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
189235678f [Sema] Move member chain transformation into precheck
Move the analysis and transformation of unresolved member chains into the PreCheckExpression pass in order to make sure that contextual types get hooked up properly before we actually begin generating constraints.
2020-08-26 22:42:30 -04:00
Frederick Kellison-Linn
4331e26bcd [Sema] Move UnresolvedMemberChainResultExpr creation to walkToExprPre
The old method of generating this placeholder expression caused issues when constraints had to be recursively regenerated during solving. Now, we generate UnresolvedMemberChainResultExprs in walkToExprPre, and use ASTWalker::Parent instead of ConstraintSystem::getParentExpr to find the parent of the chain tail.

This also lets us generate the chain constraints as part of the normal ConstraintGenerator visit, rather than as an extra walkToExprPost step.
2020-08-26 22:42:29 -04:00
Frederick Kellison-Linn
788d3f0953 Fix missing call diagnostic 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
b4d3237bea [CSDiagnostics] Adjust diagnostics to account that type holes in solution are UnresolvedType 2020-08-26 18:45:17 -07:00
Suyash Srijan
79b0a7ef75 [CSDiagnostics] Emit fix-its to insert requirement stubs for missing protocols in context (#33628)
* [CSDiagnostics] Emit fix-its to insert requirement stubs in editor mode for missing protocols in context

* [CSDiagnostics] Only include missing requirements in stub fix-it for missing protocols in context

The conforming type may already have declarations that could satisfy a requirement, so we shouldn't include it in the fix-it
2020-08-26 02:05:29 +01:00
Anthony Latsis
6700077344 Merge pull request #33498 from AnthonyLatsis/type-locura-3
AST: Abstract away the use of TypeLoc for function and subscript result types
2020-08-19 04:16:47 +03:00
Anthony Latsis
21faa48298 Remove FuncDecl::getBodyResultTypeLoc 2020-08-19 00:09:10 +03:00
Luciano Almeida
53cdd77044 [CSDiagnostics] Also consider PartialKeyPath a non-writable keypath on AssignmentFailure diagnostics 2020-08-17 22:46:33 -03: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
David Zarzycki
1e940c2c7e [NFC] Fix -Wsuggest-override warnings
LLVM, as of 77e0e9e17daf0865620abcd41f692ab0642367c4, now builds with
-Wsuggest-override. Let's clean up the swift sources rather than disable
the warning locally.
2020-08-13 16:17:46 -04:00
Luciano Almeida
d62e9ddd9e [Diagnostics] Minor adjustments on MissingMember tuple base and yaml message 2020-08-10 21:06:15 -03:00
Luciano Almeida
e8f1784858 [Diagnostics] Adding member subscript tailored diagnostics fixit to string literals that matches a label of labeled tuples 2020-08-09 23:20:44 -03:00