Commit Graph

490 Commits

Author SHA1 Message Date
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
Doug Gregor
6d41524fe6 [SE-0289] Finish renaming source code, tests to "result builders" 2020-10-20 22:18:51 -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
Pavel Yaskevich
6ba7ecb7c2 [ConstraintSystem] NFC: Move Constraint.h to include/swift/Sema 2020-10-08 10:45:32 -07:00
Pavel Yaskevich
087906a013 [ConstraintSystem] NFC: Move OverloadChoice.h to include/swift/Sema 2020-10-08 10:42:24 -07:00
Pavel Yaskevich
f94be56468 [Sema] Decouple ConstraintSystem and TypeChecker headers 2020-10-06 13:18:49 -07:00
Luciano Almeida
6ceda75414 [CSDiagnostic] Minor code improvement on MissingGenericArgumentsFailure addressing fixme 2020-10-04 16:19:06 -03: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
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
Pavel Yaskevich
b4d3237bea [CSDiagnostics] Adjust diagnostics to account that type holes in solution are UnresolvedType 2020-08-26 18:45:17 -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
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
038eae48f8 Adding SR-13359 diagnostics to localization yaml files and minor comment 2020-08-10 08:40:04 -03:00
Luciano Almeida
d01fed28de [Sema] Implement tailored diagnostics for MissingMemberFailure with subscripts on tuple base types 2020-08-08 21:41:22 -03: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
Pavel Yaskevich
f292eb6b6a [Diagnostics] Introduce a warning diagnostic for backward trailing closure matches
Diagnose situations when trailing closure has been matched to a specific
parameter via a deprecated backward scan.

```swift
func multiple_trailing_with_defaults(
  duration: Int,
  animations: (() -> Void)? = nil,
  completion: (() -> Void)? = nil) {}

multiple_trailing_with_defaults(duration: 42) {} // picks `completion:`
```
2020-08-07 00:30:55 -07:00
Holly Borla
19fce323c5 [Diagnostics] For array element conversion failures, emit an error message
for each element whose type variable was merged in addJoinConstraint
2020-08-06 17:58:00 -07:00
Varun Gandhi
3882beb85d [NFC] Use consistent naming scheme for predicate methods. (#33265)
bool throws() -> isThrowing(), bool async() -> isAsync()
2020-08-03 16:37:29 -07:00
Doug Gregor
2395225df7 [Type checker] Improve diagnostics for trailing closures.
The change to the forward-scanning rule regressed some diagnostics,
because we no longer generated the special "trailing closure mismatch"
diagnostic. Reinstate the special-case "trailing closure mismatch"
diagnostic, but this time do so as part of the normal argument
mismatch diagnostics so it is based on type information.

While here, clean up the handling of missing-argument diagnostics to
deal with (multiple) trailing closures properly, so that we can (e.g)
suggest adding a new labeled trailing closure at the end, rather than
producing nonsensical Fix-Its.

And, note that SR-12291 is broken (again) by the forward-scan matching
rules.
2020-07-24 08:10:54 -07:00
Luciano Almeida
f4f44d257b [CSDiagnostics] MissingOptionalUnwrapKeyPathFailure to diagnose missing unwrap on base of keypath application 2020-07-15 08:54:17 -03:00
Holly Borla
063d420e50 Merge pull request #32672 from hborla/property-wrapper-diagnostics
[Property Wrappers] Improve diagnostics for property wrappers initialized out-of-line
2020-07-07 19:07:55 -07:00
Luciano Almeida
28fb66cbaf [SR-13088] Fix false positive downcast unrelated of types that cannot be statically known (#32592)
* [TypeCheckConstraints] Adjusting cases where checked casts that cannot be determined statically were producing misleading warnings

* [tests] Adding regression tests for SR-13088

* [TypeCheckConstraints] Adjusting comment and adding an extra test case for SR13035

* [TypeCheckConstraints] Fixing typos in comments

* [AST] Moving implementation of isCollection from ConstraintSystem to AST TypeBase

* [TypeCheckConstraints] Adjusting logic to verify specific conformance to stdlib collection type before emit an downcast warning

* [TypeCheckConstraints] Creating new CheckedCastContextKind::CollectionElement to be able to verify special cases within typeCheckCheckedCast for collection elements

* [TypeCheckConstraints] Adjusting logic around generic substitution to check both subtype and supertype

* [Sema] Adding isKnownStdlibCollectionType and replacing all usages contraint system method

* [TypeChecker] Reverting fixes around array element types

* [TypeChecker] Abstract logic of check for conditional requirements on TypeChecker::couldDynamicallyConformToProtocol

* [TypeChecker] Ajdustinc can conformDynamically conform and adjust review comments

* [TypeChecker] Ajusting comments and fixing typos

* [TypeChecker] Adjusting existential and archetype logic to check inside couldDynamicConform

* [TypeChecker] Adjusting minor and adding existential check into couldDynamically conform.

* [TypeChecker] Adjusting comments
2020-07-02 22:06:29 -03:00
Holly Borla
142e9f6289 [Diagnostics] Tweak some diagnostics code to allow diagnosing a fix
anchored at a TypeRepr rather than an Expr.
2020-07-02 14:47:45 -07:00
Luciano Almeida
43fd786ae0 [SR-5688] [Sema] Handle key path component base type on MemberAccessOnOptionalBaseFailure (#32376)
* [CSDiagnostics] Adjusting MemberAccessOnOptionalBaseFailure to be able to handle key path component member base types

* [tests] Adding regression tests for SR-5688

* [CSDiagnostics] Adjusting source range to diagnose/insert the fixes in correct location

* [tests] Adjusting regression tests to handle the fixits

* [AST] Creating an helper getSourceRange function for KeyPathExpr::Component

* [ConstraintSystem] Store member base type when recording UnwrapOptionalBase fix

* [AST] Creating a new diagnostic note for removing optional from written type

* [CSDiagnostics] Adjusting logic around MemberAccessOnOptionalBaseFailure to emit the correct diagnostics and fixes

* [tests] Adjusting regression tests to add subscript and key path root cases with respective diagnostics

* [Diagnostics] Adjusting message to mention base type

* [CSDiagnostics] Better naming for method/variable that represents base source range

* [CSDiagnostics] Adjusting to use the stored base member only when member is a key path component.

* [Diagnostics] Adjusting minor typos and code

* [AST] Adjusting keypath root diagnostic note message for use unwrapped type

* [CSDiagnostics] Adjusments in MemberAccessOnOptionalBaseFailure diagnostics as per suggestion

* [tests] Adding more test cases for SR-5688

* [CSDiagnostics] Adjusting fixits for key path root and range for diagnostics

* [CSSimplify] Attempt to diagnose InsertExplicitCall for optional function return types when possible on simplifyOptionalObjectConstraint

* [tests] Adding TODO to improve the diagnostics refering to key path root infered as optional types

* [CSDiagnostics] Adjusting comments

* [CSSimplify] Adjusting logic on simplifyOptionalObjectConstraint to attempt InsertCall fix before remove unwrap

* [CSDiagnostics] Adjust the logic to use resolveType on MemberAccessOnOptionalBaseFailure construction
2020-06-25 20:07:03 -03:00
Greg Titus
c73b144ad8 Perform the unintended generic detection in simplifyMemberConstraint and define a ConstraintFix to produce the new note. 2020-06-09 09:02:42 -07:00
Greg Titus
be4e23f41e New note for users that have wrongly assumed that generic param conformances use the same separators as type conformances. 2020-06-05 18:41:33 -07:00
Pavel Yaskevich
b938f960df [Diagnostics] NFC: Rename a fix/diagnostic for missing .rawValue reference 2020-06-03 08:48:33 -07:00
Pavel Yaskevich
734f5b660c [Diagnostics] NFC: Fix typo(s) raw representative -> representable 2020-06-02 12:24:42 -07:00
Pavel Yaskevich
4d9566c028 [Diagnostics] NFC: Remove obsolete logic related to raw representable 2020-06-01 14:29:36 -07:00
Pavel Yaskevich
0e6dcabc54 [Diagnostics] Share diagnoseAsNote for raw representable diagnostics 2020-06-01 14:24:39 -07:00
Pavel Yaskevich
80c4aa6e80 [Diagnostics] NFC: Rename ValueType to ExpectedType in raw representable fix/diagnostics 2020-06-01 12:18:03 -07:00
Pavel Yaskevich
b38d11d24a [Diagnostics] Add a distinct diagnostic for use of raw representable instead of its raw value
Diagnose an attempt to pass raw representable type where its raw value
is expected instead.

```swift
enum E : Int {
  case one = 1
}

let _: Int = E.one
```

`E.one` has to use `.rawValue` to match `Int` expected by pattern binding.
2020-05-29 14:39:48 -07:00
Pavel Yaskevich
761657f398 [Diagnostics] Extract common logic for raw representable diagnostics into AbstractRawRepresentableFailure 2020-05-29 14:25:30 -07:00
Pavel Yaskevich
7034fb3eb7 [Diagnostic] Add a note to missing explicit raw representative init diagnostic 2020-05-28 16:24:59 -07:00
Pavel Yaskevich
87a0079337 [Diagnostic] Always resolve types required for raw representative construction
Since both raw representable and value types originated in
constraint system they can have type variables which need to be
resolved before types could be used in a diagnostic and fix-it.
2020-05-28 15:36:57 -07:00
Pavel Yaskevich
d6bf31cb97 [Diagnostics] Add a distinct diagnostic for missing raw representable init
Diagnose an attempt to initialize raw representable type or convert to it
a value of some other type that matches its `RawValue` type.

```swift
enum E : Int {
   case a, b, c
}

let _: E = 0
```

`0` has to be wrapped into `E(rawValue: 0)` and either defaulted via `??` or
force unwrapped to constitute a valid binding.
2020-05-27 17:26:11 -07:00
Hamish Knight
9e2cdf49b3 Merge pull request #31506 from hamishknight/hello-operator 2020-05-23 09:48:21 -07:00
Suyash Srijan
f026c61dce [ConstraintSystem] Disallow use of enum case as a key path component (#31969) 2020-05-22 20:41:45 +01:00
Hamish Knight
cc062ee2bb Fix precedencegroup and operator decl lookup
Re-implement operator and precedencegroup decl
lookup to use `namelookup::getAllImports` and
existing decl shadowing logic. This allows us to
find operator decls through `@_exported` imports,
prefer operator decls defined in the same module
over imported decls, and fixes a couple of other
subtle issues.

Because this new implementation is technically
source breaking, as we can find multiple results
where we used to only find one result, it's placed
behind the new Frontend flag
`-enable-new-operator-lookup` (with the aim of
enabling it by default when we get a new language
mode).

However the new logic will always be used if the
result is unambiguous. This means that e.g
`@_exported` operators will be instantly available
as long as there's only one candidate. If multiple
candidates are found, we fall back to the old
logic.

Resolves SR-12132.
Resolves rdar://59198796.
2020-05-18 14:33:43 -07:00
Pavel Yaskevich
7e4eb9cee5 [Diagnostics] Diagnose inability to infer type of a closure parameter 2020-05-15 01:13:06 -07:00
Luciano Almeida
02c454c976 [Diagnostics] Diagnose that we cannot infer the key path type when binding to a hole 2020-05-11 18:08:40 -03:00
Artem Chikin
7aed042817 Add fix on Keypath -> Function with multiple arguments type mismatch.
When simplifying a keypath constraint with a function type binding, single-parameter functions have the parameter type and the return type matched against the keypath root and value; whereas multiple-parameter functions cause an ambiguous failure (in `simplifyKeyPathConstraint`).

Resolves rdar://problem/57930643
2020-05-06 19:15:08 -07:00
Pavel Yaskevich
5a7c70dcc4 [Diagnostics] NFC: Add isRawRepresentable/conformsToKnownProtocol helpers into FailureDiagnostic 2020-05-01 13:46:21 -07:00
Pavel Yaskevich
db6801b4b5 [Diagnostics] Add getRawType which allows to retrieve type associated with ASTNode
This is useful when diagnostic needs to check something about type
variables involved in a particular type e.g. whether type variable
has been defaulted.
2020-05-01 12:44:34 -07:00
Pavel Yaskevich
ee6c228214 [Diagnostics] NFC: Move is{Array, Collection}Type helpers into FailureDiagnostic 2020-05-01 12:21:15 -07:00
Pavel Yaskevich
99ef865aac [Diagnostics] Switch FailureDiagnostic to use ASTNode instead of TypedNode 2020-04-29 17:03:45 -07:00
Luciano Almeida
723a75343d [CSDiagnostics] Tailor diagnostic for define missing member when involving a collectin type 2020-04-28 17:07:12 -03:00