Commit Graph

500 Commits

Author SHA1 Message Date
Pavel Yaskevich
9231acf202 [Diagnostics] Implement a tailored diagnostic for invalid static member refs on protocol metatypes 2021-02-23 11:32:24 -08:00
Frederick Kellison-Linn
e4ea1678dc Rename HoleType to PlaceholderType
HoleType basically served the same purpose as PlaceholderType. This commit unifies the two.
2021-02-16 22:59:19 -05:00
Luciano Almeida
d55eed46e8 [Sema][CSApply] Moving some checked cast diagnostics to a fix format (#34980)
* [Sema] Implementing is runtime check always true diagnostic as a fix

* [AST] Implement getWithoutThrows on function type

* [CSSimplify] Detect that checked cast types conversion is always true and record warning fix

* [test] Some additional test cases for SR-13789

* [Sema] Fixing typo on fix name

* [Sema] Move and adjust the ConditionalCast diagnostics to the fix format

* [Sema] Remove some checked cast diagnostics from check constraints and move to fix

* [Sema] Renaming checked cast coercible types fix

* [Sema] Some adjustments and rewrite on the logic for downcast record fix

* [Sema] Move logic of runtime function type to AllowUnsupportedRuntimeCheckedCast::attempt

* [Sema] Abstract checked cast fix logic to static function and minor adjustments

* [Sema] Renamings from review
2021-02-10 08:31:06 -03:00
Doug Gregor
ba8819eb58 [Concurrent] Introduce concurrent function types.
Introduce `@concurrent` attribute on function types, including:
* Parsing as a type attribute
* (De-/re-/)mangling for concurrent function types
* Implicit conversion from @concurrent to non-@concurrent
- (De-)serialization for concurrent function types
- AST printing and dumping support
2021-01-27 14:22:32 -08:00
Luciano Almeida
c8ea08df78 [Sema] Creating ambiguous base for none member warning diagnostic as a fix 2020-12-05 22:48:09 -03:00
Doug Gregor
50cdddaf95 [Concurrency] Enable implicit conversion from synchronous -> asynchronous. 2020-12-03 12:44:21 -08:00
Pavel Yaskevich
85181360b1 Merge pull request #34810 from xedin/rdar-66709164
[ConstraintSystem] Detect and diagnose extraneous return(s) in result build body
2020-12-02 15:51:10 -08:00
Luciano Almeida
ac65e6fcc4 [Sema] Detect if we should use a conditional binding when recording the CoerceToCheckedCast fix 2020-12-01 09:03:17 -03:00
Pavel Yaskevich
03ede7427c [Diagnostics] Diagnose use of one or more return statements in a result builder body 2020-11-19 17:21:00 -08:00
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
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