Commit Graph

616 Commits

Author SHA1 Message Date
Pavel Yaskevich
a8d44bc9ce Merge pull request #32558 from xedin/fix-req-conformace-assessment
[ConstraintSystem] Adjust recording of "fixed" requirements to avoid conflicts
2020-06-26 15:28:13 -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
Pavel Yaskevich
f7ef6d411c [Diagnostics] Augment conformance failure to with a note about enum with associated values
If the problem is related to an operator and argument is an enum
with associated values mention that conformances to `Equatable`
and `Comparable` are not synthesized in such cases.
2020-06-25 14:44:28 -07:00
Robert Widmann
399a5510d2 [NFC] Inline TypeChecker::getStringType 2020-06-11 12:21:35 -07:00
Robert Widmann
f02a0f0439 [NFC] Remove TypeChecker::getSubstringType
Inline it into its only caller
2020-06-11 12:21:35 -07:00
Robert Widmann
ca728917e1 Merge pull request #32138 from AnthonyLatsis/eliminate-typeloc
Sema: Remove TypeLoc from ExplicitCastExpr (via TypeExpr)
2020-06-10 11:28:50 -07:00
Greg Titus
f7fd83de3a Merge pull request #32220 from gregomni/unintended_generic_param
[QoI] Detect unintended generic params and provide a note and fixit.
2020-06-09 12:49:19 -07: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
Anthony Latsis
4b4634141f Sema: Remove TypeLoc from ExplicitCast 2020-06-09 15:20:25 +03:00
Doug Gregor
7d4da10843 Merge pull request #32200 from DougGregor/single-expression-closure-cleanup
[AST] Clean up handling of single-expression closures
2020-06-05 21:02:58 -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
Doug Gregor
836bc57fe5 [AST Walker] Stop visiting the bodies of closures as expressions.
Single-expression closures have always been traversed differently
from multi-statement closures. The former were traversed as if the
expression was their only child, skipping the BraceStmt and implicit
return, while the later was traversed as a normal BraceStmt.
Unify on the latter treatment, so that traversal

There are a few places where we unintentionally relied on this
expression-as-child behavior. Clean those up to work with arbitrary
closures, which is an overall simplification in the logic.
2020-06-04 23:06:32 -07:00
Pavel Yaskevich
651503b147 Merge pull request #32128 from xedin/adjust-raw-representable-diag
[Diagnostics] Refactor diagnostics related to raw representable types
2020-06-03 11:26:22 -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
0f6665cae6 [Diagnostics] Adjust fix-it when .rawValue is missing from optional type 2020-06-02 12:50:13 -07:00
Pavel Yaskevich
734f5b660c [Diagnostics] NFC: Fix typo(s) raw representative -> representable 2020-06-02 12:24:42 -07:00
Pavel Yaskevich
f9e99ed35c [Diagnostics] NFC: Align diagnoseAsNote with diagnoseAsError for AbstractRawRepresentableFailure 2020-06-02 12:15:54 -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
Anthony Latsis
9fd1aa5d59 [NFC] Pre- increment and decrement where possible 2020-06-01 15:39:29 +03: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
03938f9ec5 [Diagnostics] NFC: Remove obsolete logic from ContextualFailure::tryRawRepresentableFixIts 2020-05-29 12:14: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
bd65f7418b [Diagnostics] Add fix-its to suggest explicit raw representable initialization
This makes logic in `ContextualFailure::tryRawRepresentableFixIts`
partially obsolete.
2020-05-28 13:37:46 -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
1de3d0dbef Merge pull request #31943 from owenv/line-and-col 2020-05-25 17:57:09 -07:00
Pavel Yaskevich
9eb22c0874 Merge pull request #31982 from xedin/improve-generic-param-diags
[Diagnostics] Strip off unrelated optionals from generic parameter di…
2020-05-25 15:06:19 -07:00
Pavel Yaskevich
f55ce19127 [Diagnostics] Strip off unrelated optionals from generic parameter diagnostics
In situations where left-hand side requires value-to-optional
promotion which ends up in type mismatch let's not mention
optionals in the diagnostic because they are unrelated e.g.

```swift
func test(_: UnsafePointer<Int>??) {}

var value: Float = 0
test(&value)
```

In this example `value` gets implicitly wrapped into a double optional
before `UnsafePointer<Float>` could be matched against `UnsafePointer<Int>`
associated with the parameter.

Diagnostic is about generic argument mismatch `Float` vs. `Int`
and shouldn't mention any optionals.
2020-05-22 15:12:23 -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
Owen Voorhees
45bc578ae5 [SourceManager] Rename line and column APIs for clarity 2020-05-21 12:54:07 -05:00
Pavel Yaskevich
3efa052aae [Diagnostics] Adjust r-value -> l-value diagnostic to account for ArgumentAttribute 2020-05-18 13:09:56 -07:00
Pavel Yaskevich
f68e8d2436 [Diagnostics] Don't diagnose inability to infer closure parameter if contextual couldn't be established
If closure is an argument to a call to a missing member or invalid
contextual member reference let's not diagnose problems related to
inability to infer parameter types because root issue is that context
for closure inference couldn't be established.
2020-05-15 01:13:06 -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
7c19460d3b [test] Adding SR-12745 test cases 2020-05-12 17:58:10 -03: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
Saleem Abdulrasool
09975d1253 sprinkle llvm_unreachable for covered switches (NFC)
Annotate the covered switches with `llvm_unreachable` to avoid the MSVC
warning which does not recognise the covered switches.  This allows us
to avoid a spew of warnings.
2020-05-07 11:05:35 -07: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
1f0ecc6e92 Merge pull request #31511 from LucianoPAlmeida/SR-12725-diagnostics-generic-argument
[SR-12725] Diagnose unhandled generic argument mismatch involving FunctionArgument
2020-05-03 00:44:41 -07:00
Luciano Almeida
5ac1926f50 [CSDiagnostics] Break to the fallbacks when no specific diagnostics is found 2020-05-03 02:09:00 -03:00
Pavel Yaskevich
786b16ce82 [Diagnostics] NFC: Switch to which doesn't require constraint system 2020-05-01 14:28:15 -07:00
Pavel Yaskevich
5a7c70dcc4 [Diagnostics] NFC: Add isRawRepresentable/conformsToKnownProtocol helpers into FailureDiagnostic 2020-05-01 13:46:21 -07:00
Pavel Yaskevich
bf4c3b7bdd [Diagnostics] Use data from associated solution while diagnosing missing generic arguments 2020-05-01 13:04:56 -07:00
Pavel Yaskevich
2d1e408170 [Diagnostics] Use solution for verify presence of fix in diagnoseUseOfReferenceEqualityOperator 2020-05-01 12:52:58 -07:00
Pavel Yaskevich
b405f7c543 [Diagnostics] Avoid direct use of constraint system by MissingArgumentsFailure::isMisplacedMissingArgument 2020-05-01 12:45:48 -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
490548f70b [Diagnostics] Fix ContextualFailure to use solution data for hasAppliedSelf 2020-05-01 11:02:40 -07:00
Pavel Yaskevich
b4c73abdbc [Diagnostics] Fix MissingConformanceFailure::diagnoseAsError to use solution to retrieve fixes 2020-05-01 10:55:25 -07:00