Commit Graph

1245 Commits

Author SHA1 Message Date
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
Luciano Almeida
041051e1ed [CSDiagnostics] Tailor diagnostic for define missing member when involves array literal and unresolved member 2020-04-28 12:35:28 -03:00
Slava Pestov
742bd98402 Sema: Remove ConformanceCheckOptions::SkipConditionalRequirements
All callers can trivially be refactored to use ModuleDecl::lookupConformance()
instead. Since this was the last flag in ConformanceCheckOptions, we can remove
that, too.
2020-04-25 00:14:24 -04:00
Joe Groff
b4c7a7e85d Merge pull request #31224 from AnthonyLatsis/rename-getfullname-2
AST: Rename getFullName -> getName on ValueDecl & MissingMemberDecl
2020-04-24 12:51:28 -07:00
Robert Widmann
09db2902d2 Strip TypeExpr of its TypeLoc
Remove duplication in the modeling of TypeExpr. The type of a TypeExpr
node is always a metatype corresponding to the contextual
type of the type it's referencing. For some reason, the instance type
was also stored in this TypeLoc at random points in semantic analysis.

Under the assumption that this instance type is always going to be the
instance type of the contextual type of the expression, introduce
a number of simplifications:

1) Explicit TypeExpr nodes must be created with a TypeRepr node
2) Implicit TypeExpr nodes must be created with a contextual type
3) The typing rules for implicit TypeExpr simply opens this type
2020-04-23 17:04:38 -07:00
Pavel Yaskevich
9f02f782f3 [Diagnostics] NFC: Switch dyn_cast/get of anchor to either castToExpr or getAsExpr 2020-04-23 01:13:13 -07:00
Pavel Yaskevich
4b1aa29149 [ConstraintSystem] NFC: Adjust all uses of locator anchors to work with TypedNode 2020-04-23 01:13:13 -07:00
Pavel Yaskevich
398f37842a [ConstraintSystem] Elevate TypedNode access helpers up to the namespace
Originally such accessors were only useful for `FailureDiagnostic` but
now since `ConstraintLocator` is anchored with `TypedNode` it makes sense
to make them universally accessible.
2020-04-23 01:13:13 -07:00
Pavel Yaskevich
288e286efd Merge pull request #31192 from LucianoPAlmeida/SR-12425-diagnostics
[SR-12425] Improving diagnostics for key path application on non-convertible root type
2020-04-23 00:17:49 -07:00
Luciano Almeida
721dd7780d [NFC] Minor comment adjustments 2020-04-22 23:55:58 -03:00
Anthony Latsis
74252028ca AST: Rename getFullName -> getName on ValueDecl & MissingMemberDecl 2020-04-23 05:16:55 +03:00
Luciano Almeida
094ffd6b25 [CSDiagnostics] Adjusting KeyPathRootTypeMismatchFailure implementation and message 2020-04-22 20:30:54 -03:00
Robert Widmann
78e07c1d41 Merge pull request #31159 from CodaFi/track-star
Remove Fallback Infrastructure For Evaluator-Based Dependencies
2020-04-22 15:37:48 -07:00
Luciano Almeida
6e5be5b7d4 [CSDiagnostics] Create KeyPathRootTypeMismatchFailure to diagnose key path root fail on key path application 2020-04-21 17:38:06 -03:00
Robert Widmann
48a5432cb7 [NFC] Remove ConformanceCheckFlags::InExpression
The last read of this bit was removed when the legacy referenced name tracker was deleted in the last commit.
2020-04-20 10:22:58 -07:00
Pavel Yaskevich
967b3a3c8d [Diagnostics] Adjust getCallInfo to accept TypedNode instead of expression 2020-04-17 13:28:06 -07:00