Commit Graph

760 Commits

Author SHA1 Message Date
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
Pavel Yaskevich
a05e072a6c [Diagnostics] Fix RequirementFailure::getConformanceForConditionalReq to use data from solution 2020-05-01 10:52:25 -07:00
Pavel Yaskevich
99ef865aac [Diagnostics] Switch FailureDiagnostic to use ASTNode instead of TypedNode 2020-04-29 17:03:45 -07:00
Pavel Yaskevich
a400c74c47 Merge pull request #31366 from LucianoPAlmeida/SR-12672-diagnostics
[SR-12672] Tailored diagnostics for missing member involving array literal default to any element
2020-04-28 16:10:46 -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
Robert Widmann
a6fc9b3679 Merge pull request #31253 from CodaFi/casting-call
Strip TypeExpr of its TypeLoc
2020-04-28 09:45:53 -07:00
Luciano Almeida
4f7ad54b5f [tests] Add tests for SR-12672 2020-04-28 13:07:09 -03:00