Commit Graph

534 Commits

Author SHA1 Message Date
Hamish Knight
a61223a255 [CS] Visit all fixed bindings for constraint re-activation (#30886)
[CS] Visit all fixed bindings for constraint re-activation
2020-04-10 12:27:47 -07:00
Hamish Knight
d69a42d656 [CS] Preserve compatibility for collection coercions
Previously we could allow some invalid coercions to
sneak past Sema. In most cases these would either
cause crashes later down the pipeline or
miscompiles. However, for coercions between
collections, we emitted somewhat reasonable code
that performed a force cast.

This commit aims to preserve compatibility with
those collection coercions that previously
compiled, and emits a warning telling the user to
use either 'as?' or 'as!' instead.
2020-04-10 10:16:07 -07:00
Pavel Yaskevich
42bdfc9bc6 [Diagnostics] Remove unsafe getRestrictionFor method 2020-04-09 15:35:14 -07:00
Pavel Yaskevich
6f2af1f433 [Diagnostics] Replace getChoiceFor with getCalleeOverloadChoiceIfAvailable
New name is more consistent with existing `getOverloadChoiceIfAvailable`
and allows us to clean up a couple of places where `getCalleeLocator` was
used directly before.
2020-04-09 12:44:16 -07:00
Pavel Yaskevich
6f83c08aae [Diagnostics] Remove obsolete getResolvedMemberRef 2020-04-08 16:09:08 -07:00
Pavel Yaskevich
a84e0b70fc [Diagnostics] Obsolete and remove HasComplexLocator field from diagnostic
This was useful when CSDiag was still in play but since everything
has been ported this is no longer useful.
2020-04-08 15:03:42 -07:00
Luciano Almeida
08904ffe3f [SR-12242] Apply to Arg involving ConstraintLocator::GenericArgument diagnostics improvement (#30814)
* [CSDiagnostics] Handle arg to param generic when locator points to ConstraintLocator::GenericArgument

* [test] Add SR-12242 test case

* [CSDiagnostics] Handle arg to param on Generic mismatch as a fallback diagnostic

* [CSDiagnostics] Make assign diagnostics in GenericMismatchFailure handle more cases

* [test] Adding test cases for assign expr in GenericMismatch diagnostics

* [CSDiagnostics] Improving inout to pointer argument conversions with optionals diagnostics
2020-04-06 10:25:02 -07:00
Robert Widmann
630d0f631a Merge pull request #30606 from AnthonyLatsis/rename-getfullname
[NFC] Preparations to address the «Rename to getName?» TODO on ValueDecl::getFullName
2020-04-01 09:00:04 -07:00
Pavel Yaskevich
f95cabb745 [ConstraintSystem] Allow sequence element mismatch fix to produce new holes
Type on the right-hand side of the element conversion/pattern match
should be allowed to have holes to be able to diagnose failures with
structurally incompatible types.

Resolves: rdar://problem/60832876
2020-03-30 17:48:46 -07:00
Anthony Latsis
c63b737e92 Collapse all indirect equivalents to ValueDecl::getBaseIdentifier 2020-03-29 00:36:01 +03:00
Anthony Latsis
d0ae3ee580 [AST] Replace FuncDecl::getName & EnumElementDecl::getName with ValueDecl::getBaseIdentifier 2020-03-29 00:35:51 +03:00
Holly Borla
da715f87c5 [Diagnostics] Support diagnosing references to operators without argument
application in MissingConformanceFailure::diagnoseAsAmbiguousOperatorRef
2020-03-26 08:40:32 -07:00
Pavel Yaskevich
972de2e657 Merge pull request #30627 from LucianoPAlmeida/SR-12382-improve-pointer-conversion-mismatch-diag
[SR-12382] Improve optional pointer conversion mismatch diagnostics
2020-03-25 02:22:59 -07:00
Luciano Almeida
829152bdb4 [CSDiagnostics] Handle optional Inout to typed pointer conversion diagnostics on generic mismatch 2020-03-25 01:51:30 -03:00
Anthony Latsis
667bec0f21 Merge pull request #30578 from AnthonyLatsis/memb-fail-qoi
[DiagQoI] Improve fallback fixits for static member on instance errors
2020-03-23 19:31:10 +03:00
Anthony Latsis
572f0544a2 [DiagQoI] Improve fallback fixits for static member on instance error 2020-03-23 08:27:55 +03:00
Pavel Yaskevich
89933c67da [ConstraintSystem] Don't allow explicit closure result to be implicitly converted to Void
It's allowed to convert a single statement closure from `(...) -> T` to `(...) -> Void`
_only_ if there is no explicit `return` in the body.

Resolves: [SR-12277](https://bugs.swift.org/browse/SR-12277)
Resolves: rdar://problem/52204414
2020-03-19 16:59:17 -07:00
Dmitri Gribenko
841eeb05b0 Merge pull request #30403 from MForster/forster/string-fixes
Cherry-pick StringRef->std::string conversion fixes into `master`
2020-03-17 12:09:36 +01:00
Pavel Yaskevich
7800a04de3 [Diagnostics] Adjust "missing arguments" diagnostic to store parameter indices directly
This helps to avoid allocating new type variables (which shouldn't be done regardless)
to store parameter indices when `missing arguments` diagnostic is used by other diagnostics.
2020-03-13 16:55:37 -07:00
Pavel Yaskevich
3ab8710329 [Diagnostics] Cleanup use of constraint system by ConstraintFix/FailureDiagnostic 2020-03-13 15:02:10 -07:00
Pavel Yaskevich
52cf60122b [Diagnostics] Switch isMisplacedMissingArgument to use a solution 2020-03-13 12:46:38 -07:00
Pavel Yaskevich
0fc9d1b84a [Diagnostics] Move getFunctionArgApplyInfo to Solution
Instead of relying on constraint system having solution applied
let's pass a solution directly to `getFunctionArgApplyInfo`.
2020-03-13 12:46:25 -07:00
Fred Riss
259d78a350 Adapt to llvm.org StringRef API change 2020-03-13 19:08:22 +01:00
Pavel Yaskevich
af4afe3fbc [Diagnostics] Switch FailureDiagnostic to use a solution
Make diagnostics stateless by providing them with a solution
instead of applying a solution back to constraint system and
using constraint system. Latter doesn't work well when there
is an ambiguity and multiple solutions are available instead
of one.
2020-03-13 10:37:23 -07:00
Pavel Yaskevich
7c19d1ccd1 [ConstraintSystem] Remove baseCS since CSDiag has been removed
There is no more sub-expression re-typechecking so no need to keep
parent constraint systems around.
2020-03-06 09:35:52 -08:00
Pavel Yaskevich
f7b264583d [Diagnostic] Don't fix partial mismatch for sub-types associated with optional conversion
If mismatch detected by `repairFailures` is related to a complex
wrapped value of optional type formed from optional-to-optional
or value-to-optional conversion let's not try to fix it directly
but let `simplifyRestrictedConstraintImpl` record a top-level fix
for more context.

Resolves: rdar://problem/59703585
2020-03-03 00:24:34 -08:00
Pavel Yaskevich
9db7144bbc [CSDiagnostics] Handle try? contextual mismatch directly
It detends on a situation whether try? would get a type inferred
so the mismatch is against a contextual type, or contextual type
would be used as a type of `try?` and fail comparsion with inner
expression type. In either case the mismatch is contextual.
2020-03-02 09:02:56 -08:00
Pavel Yaskevich
389e84fc55 Merge pull request #30115 from LucianoPAlmeida/nfc-abstract-is-stdlib
[NFC] Abstracting isStdlibType and isStdLibDecl logic into Type and Decl
2020-02-28 13:32:32 -08:00
Luciano Almeida
f4b530fb95 [NFC] Abstracting isStdlibType and isStdLibDecl logic into Type and Decl 2020-02-28 07:40:08 -03:00
Slava Pestov
019452f9af Sema: Diagnose unbound method references on 'super.'
This is something I noticed by inspection while working on
<https://bugs.swift.org/browse/SR-75>.

Inside a static method, 'self' is a metatype value, so
'self.instanceMethod' produces an unbound reference of type
(Self) -> (Args...) -> Results.

You might guess that 'super.instanceMethod' can similarly
be used to produce an unbound method reference that calls
the superclass method given any 'self' value, but unfortunately
it doesn't work.

Instead, 'super.instanceMethod' would produce the same
result as 'self.instanceMethod'. Maybe we can implement this
later, but for now, let's just diagnose the problem.

Note that partially-applied method references with 'super.'
-- namely, 'self.staticMethod' inside a static context, or
'self.instanceMethod' inside an instance context, continue
to work as before.

They have the type (Args...) -> Result; since the self value
has already been applied we don't hit the representational
issue.
2020-02-27 17:28:23 -05:00
Doug Gregor
d607d3a068 [Constraint system] Custom diagnostics for failed pattern matches.
Extend the constraint system’s diagnostics with specific handling for
matching an enum element pattern that has a subpattern (i.e., to capture
associated values) against an enum case that does not have any associated
value. This brings diagnostics for the new code path on par with the existing
diagnostics of coercePatternToType.
2020-02-24 00:48:15 -08:00
Pavel Yaskevich
2dccdbfabf [ConstraintSystem] NFC: Remove workarounds related to (now deprecated) CSDiag 2020-02-18 10:13:09 -08:00
Pavel Yaskevich
ca91a1bee0 [ConstraintSystem] Detect and diagnose OoO arguments in call to binary functions/operators
Identify problems like:

```swift
func foo(_ x: Int, _ y: String) {}

func bar(a: Int, b: String) {
  foo(b, a) // Instead of `foo(a, b)`
}
```

Where arguments are out-of-order and repair it by using OoO fix on the
parent locator.
2020-02-17 16:09:11 -08:00
Pavel Yaskevich
df21cbf85c [ConstraintSystem] Ignore attempt to bind type var to dependent member with incorrect base
Just like in cases where both sides are dependent member types
with resolved base that can't be simplified to a concrete type
let's ignore this mismatch and mark affected type variable as a hole
because something else has to be fixed already for this to happen.
2020-02-17 16:09:11 -08:00
Pavel Yaskevich
355148dbe8 Merge pull request #29746 from hborla/ambiguity-with-fixes
[Diagnostics] Refactor diagnoseAmbiguityWithFixes.
2020-02-13 02:42:43 -08:00
Pavel Yaskevich
5437622d2d [Diagnostics] Diagnose ambiguity with conflicting arguments to generic parameters
It's done by first retrieving all generic parameters from each solution,
filtering boundings into distrinct set and diagnosing any differences.

For example:

```swift
func foo<T>(_: T, _: T) {}
func bar(x: Int, y: Float) {
  foo(x, y)
}
```
2020-02-12 17:53:31 -08:00
Robert Widmann
054d7b9913 Merge pull request #29713 from CodaFi/unused-unwanted-unloved
[Gardening] Silence Some Warning Spew
2020-02-11 15:46:16 -08:00
Suyash Srijan
211394099f [CSDiagnostics] Offer a fix-it to insert a return type placeholder when returning from a void function (#29747)
* [CSDiagnostics] Offer a fix-it to insert a return type when returning from a void function

* [CSDiagnostics] Make sure the function name is not empty

The function name will be empty in some cases, for example for property setters. In cases where the function name is empty, skip the note and fix-it.

* [Test] Update existing diagnostics
2020-02-11 10:25:16 +00:00
Robert Widmann
d2360d2e8c [Gardening] dyn_cast -> isa 2020-02-07 16:09:31 -08:00
Pavel Yaskevich
2875aa8e2b [Diagnostics] Diagnose an attempt to init/use dictionary with array literal in CSGen
It's much easier to detect that contextual type is a dictionary
but expression is an array literal while generating constraints.
2020-02-06 09:32:07 -08:00
Pavel Yaskevich
c5ae6c96a9 [ConstraintSystem] Detect missing/extraneous arguments even if there is optional injection required
If parameter type is optional let's ignore that since argument could
be either optional itself or be injected into optional implicitly.

```swift
func foo(_: ((Int, Int) -> Void)!) {}

foo { _ in } // Missing second closure parameter
```
2020-02-05 12:11:01 -08:00
Pavel Yaskevich
506cd7d858 [ConstraintSystem] Let optional chaining infer a type from sub-expression even with contextual mismatch
Just like in case of `try?` it makes it easier to distinguish between
missing optional unwrap and contextual type mismatch.
2020-02-05 12:11:01 -08:00
Pavel Yaskevich
fb0a484a08 [ConstraintSystem] Let try? infer type from sub-expression even with contextual mismatch
This helps to diagnose contextual mismatches like `Int? vs. Bool`
instead of suggesting to unwrap the optional which would still
produce an incorrect type.
2020-02-05 12:11:01 -08:00
Pavel Yaskevich
956b9f27b4 Merge pull request #29628 from owenv/condition_diags
[Diagnostics] Improve diagnostics for optional/integer as boolean condition
2020-02-04 08:49:36 -08:00
Owen Voorhees
166555c34f [Diagnostics] Better diagnostic for integer used as a boolean condition 2020-02-03 21:20:41 -08:00
Owen Voorhees
4aca39e18e [Diagnostics] Provide a better fix-it when trying to boolean-negate an optional 2020-02-03 17:40:03 -08:00
swift-ci
b6d9dcca46 Merge pull request #29589 from DougGregor/expr-type-check-flag-cleanups 2020-01-31 23:51:20 -08:00
Doug Gregor
c5ed8d67a9 [Constraint solver] Fix tautological assert. 2020-01-31 21:40:39 -08:00
swift-ci
8c8f5b1eb1 Merge pull request #29588 from DougGregor/silence-the-listeners 2020-01-31 20:02:13 -08:00
Doug Gregor
4b0e7b2780 [Type checker] Sink logic for @autoclosure default parameters into the solver
Rather than use an ExprTypeCheckListener subclass to introduce the
autoclosure expression, do it at the end of solving.
2020-01-31 18:20:46 -08:00