Commit Graph

269 Commits

Author SHA1 Message Date
Pavel Yaskevich
103630296d [Diagnostics] Add a getLoc method to FailureDiagnostic 2020-04-14 11:30:11 -07:00
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
faba29a55f [Diagnostics] Diagnose key path reference to initializer methods. 2020-03-28 16:32:08 -03: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
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
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
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
Pavel Yaskevich
2dccdbfabf [ConstraintSystem] NFC: Remove workarounds related to (now deprecated) CSDiag 2020-02-18 10:13:09 -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
217c343eb6 [Diagnostics] NFC: Fix name shadowing diagnostic comment to refer to max 2020-01-29 09:14:25 -08:00
Pavel Yaskevich
c9c20afe27 [Diagnostics] Port name shadowing diagnostics
Diagnose an attempt to reference a top-level name shadowed by
a local member e.g.

```swift
extension Sequence {
  func test() -> Int {
    return max(1, 2)
  }
}
```

Here `min` refers to a global function `min<T>(_: T, _: T)` in `Swift`
module and can only be accessed by adding `Swift.` to it, because `Sequence`
has a member named `min` which accepts a single argument.
2020-01-29 09:14:24 -08:00
Pavel Yaskevich
ec3b783380 [Diagnostics] Improve diagnostic for invalid conversion to AnyObject 2020-01-29 00:37:39 -08:00
Doug Gregor
133439dcbb [Constraint solver] Request contextual type information per expression.
When requesting information about the contextual type of a constraint
system, do so using a given expression rather than treating it like
the global state that it is.
2020-01-23 11:46:17 -08:00
Luciano Almeida
68e09d64fd [CSFix] Creating object literal module import fix 2020-01-21 11:54:26 -03:00
Luciano Almeida
fb12c09188 [NFC] Fixing minor comments that should be docs and minor call 2020-01-20 21:35:22 -03:00
Holly Borla
834eee6f4e [Diagnostics] Implement MissingArgumentsFailure::diagnoseAsNote in order
to diagnose ambiguities due to missing arguments.
2020-01-07 17:37:38 -08:00
Luciano Almeida
64f8a6bd42 [CSDiagnostics] Renaming ContextualFailure CoerceExpr method naming 2020-01-06 14:37:27 -03:00
Luciano Almeida
a1bf54af51 [CSDiagnostics] Extract diagnostic for CoerceExpr to function 2020-01-04 23:41:14 -03:00
Pavel Yaskevich
8bcc192591 [Diagnostics] Diagnose inability to infer (complex) closure return type 2019-12-19 12:16:30 -08:00
Pavel Yaskevich
5ba2e59c63 Merge pull request #28752 from xedin/simplify-potential-binding
[ConstraintSystem] Record originator constraint for each type variable binding
2019-12-13 11:50:02 -08:00
Pavel Yaskevich
382013f788 [Diagnostics] Convert missing @escaping diagnostic to contextual failure
This gives diagnostic access to both sides of a conversion/binding
which makes it easier to diagnose errors associated with generic parameters.
2019-12-12 12:42:25 -08:00
Pavel Yaskevich
cc50b46345 [Diagnostics] Preserve raw from/to types in contextual mismatch diagnostic
This is useful in some situations where access to type variable(s)
helps to diagnose the problem properly e.g. if it's a conversion
to generic parameter.
2019-12-12 12:42:19 -08:00
Holly Borla
3d1ab4da67 Merge pull request #28712 from hborla/function-parameter-mismatch-diagnostics
[ConstraintSystem] Port function parameter type mismatch diagnostics.
2019-12-11 14:33:07 -08:00
Holly Borla
51c7c8c8f1 [ConstraintSystem] Port function parameter type mismatch diagnostics. 2019-12-11 10:45:52 -08:00
Brent Royal-Gordon
addbe3e5ed [NFC] Thread DeclNameRef through most of the compiler
This huge commit contains as many of the mechanical changes as possible.
2019-12-11 00:55:18 -08:00
Holly Borla
edb4e70d66 Merge pull request #28600 from hborla/tuple-mismatch-diagnostics
[ConstraintSystem] Port tuple type mismatch diagnostics
2019-12-09 13:26:34 -08:00
Holly Borla
50abedd45c [Diagnostics] Keep track of the indices of the tuple elements whose
types do not match in AllowTupleTypeMismatch/TupleContextualFailure.
2019-12-09 11:04:34 -08:00
Pavel Yaskevich
21a8b3c57d [Diagnostics] Port tailored diagnostics for missing dynamicallyCall methods 2019-12-06 16:43:18 -08:00
Holly Borla
1e013a02cf [ConstraintSystem] Move FailureDiagnostic::getFunctionArgApplyInfo
into `ConstraintSystem`.
2019-12-06 15:43:39 -08:00
Holly Borla
f9a1ab28f4 [ConstraintSystem] Port tuple type mismatches to the new framework 2019-12-06 13:12:57 -08:00
Hamish Knight
a97328dcbf [CS] Use a MapVector to cache resolved overloads
Rather than maintaining a linked list of overload
choices, which must be linearly searched each time
we need to lookup an overload at a given callee
locator, use a MapVector which can be rolled back
at the end of a scope.

Remove ResolvedOverloadSetListItem in favor of
using SelectedOverload, which avoids the need to
convert between them when moving from
ConstraintSystem to Solution.
2019-12-05 14:47:52 -08:00
Pavel Yaskevich
3c5290c78c [Diagnostics] Diagnose inability to infer contextual base type for member ref 2019-12-03 12:07:16 -08:00
Pavel Yaskevich
34f5b52db1 [Diagnostics] Diagnose ambiguities related to contextual type mismatch
If none of the candidates produce expected contextual type, record
all of the posibilities to produce a note per and diagnose this as
contextual type mismatch instead of a reference ambiguity.
2019-12-03 12:07:15 -08:00
Pavel Yaskevich
a9f11445c0 [Diagnostics] Diagnose an attempt to assign a value to an overloaded name
Example:

```swift
struct X {
}

func X(_: Int) -> Int {
  return 42
}

X = 42
```
2019-12-03 12:07:15 -08:00
Slava Pestov
2e65a14ed4 Merge pull request #28372 from slavapestov/typecheck-decl-primary
Kill ClosuresWithUncomputedCaptures and split off TypeCheckDeclPrimary.cpp from TypeCheckDecl.cpp
2019-11-20 14:29:31 -05:00
Pavel Yaskevich
38a6cfaad1 [CSDiagnostic] Convert force optional unwrap diagnostic into a contextual one
Record both sides of conversion where a form of force unwrap is
necessary to be able to produce tailored diagnostics such as for
an attempt to use optional type as a boolean.
2019-11-19 15:15:29 -08:00
Slava Pestov
ef05accd31 Sema: Remove even more vestigial TypeChecker usages 2019-11-19 17:40:00 -05:00
Pavel Yaskevich
a7bc52fd9a Merge pull request #28197 from xedin/handle-single-pd-arg-mismatch
[Diagnostics] Produce a tailored diagnostic for property wrapper argu…
2019-11-11 15:13:56 -08:00
Pavel Yaskevich
08f8f4191d [Diagnostics] Produce a tailored diagnostic for property wrapper argument mismatch
Diagnose an attempt to initialize a property, which has a property
wrapper, with a value of an incorrect type.
2019-11-11 12:59:28 -08:00
Robert Widmann
7bad9aacc3 Drop the TypeChecker out of ConstraintSystem 2019-11-10 13:26:47 -08:00
Doug Gregor
bc926f7eb7 [Constraint system] Drop the root expression from FailureDiagnostic.
We're not using it for anything, now.
2019-11-08 22:38:49 -08:00
Doug Gregor
c744066c52 [Constraint solver] Stop using the "root expression" in failure diagnostics.
We're still using the root expression to find the parent map, but we're not
falling back to it indiscriminately. Use the parent of the anchor (or
appropriate substitute) instead so we have a better handle on which
expression we're diagnosing for.
2019-11-08 21:26:04 -08:00
Pavel Yaskevich
6d02fb7815 Merge pull request #28057 from xedin/assign-diags
[Diagnostics] Port the rest of assignment diagnostics to the new framework
2019-11-06 00:11:08 -08:00
Robert Widmann
53f2974e27 [NFC] Remove unnecessary TypeCheckers from sequence folding 2019-11-05 20:30:40 -08:00