Commit Graph

490 Commits

Author SHA1 Message Date
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
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
Pavel Yaskevich
12a63ce907 [ConstraintSystem] Switch getContextualType and its variants to use TypedNode 2020-04-23 01:13:13 -07:00
Pavel Yaskevich
e5c94bfa45 [Diagnostics] Switch FailureDiagnostic constructor to accept TypedNode as an anchor 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
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
Luciano Almeida
f8cc9b52fe [tests] Adjusting SR-12425 diagnostics tests 2020-04-21 21:08:37 -03: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
Pavel Yaskevich
967b3a3c8d [Diagnostics] Adjust getCallInfo to accept TypedNode instead of expression 2020-04-17 13:28:06 -07:00
Pavel Yaskevich
4ea7f3bbb1 [Diagnostics] Add helper functions to work with anchors - {castTo, getAs, is}Expr 2020-04-17 13:15:12 -07:00
Pavel Yaskevich
6335a4f2ef [Diagnostics] Resolve const-ness problems introduced by TypedNode
Since `TypedNode` elements are all marked as `const` diagnostics
need to get some of the APIs adjusted to support passing `const Expr *`.
2020-04-17 11:43:09 -07:00
Pavel Yaskevich
08e09fc685 [Diagnostics] Switch getType to use TypedNode 2020-04-17 11:43:09 -07:00
Pavel Yaskevich
66a07bab95 [Diagnostics] Switch getContextualType* to use TypedNode 2020-04-17 11:43:09 -07:00
Pavel Yaskevich
71ab19bdce [Diagnostics] Switch getConstraintLocator variants to accept TypedNode 2020-04-17 11:43:09 -07:00
Pavel Yaskevich
f5714bf50d [Diagnostics] Switch get{Raw}Anchor to return TypedNode
In preparation to anchor `ConstraintLocator` from `TypedNode`
let's refactor diagnostics (which is the biggest user of locators)
to support `TypedNode` instead of `Expr *`.
2020-04-17 11:43:09 -07:00
Pavel Yaskevich
4ed3665f86 [Diagnostics] Provide anchors on demand instead of storing in FailureDiagnostic
This decouples `FailureDiagnostic` from expression.
2020-04-17 11:43:09 -07:00
Pavel Yaskevich
1dc6a0ac55 [Diagnostics] Allow invalid initializer ref diagnostics point to .init 2020-04-14 12:18:55 -07:00
Pavel Yaskevich
cdee9a1ce3 [Diagnostics] Use new getLoc and getSourceRange methods
Split `emitDiagnostic` into `emitDiagnostic` and `emitDiagnosticAt`.

Refactor existing diagnostics to use new methods and avoid passing
location when possible.
2020-04-14 11:30:11 -07:00
Pavel Yaskevich
5dbced972f [Diagnostics] Allow failure diagnostic implementation to extend getAnchor
Some of the diagnostics have special rules about anchor location,
let's make `getAnchor` virtual and allow sub-class to override
default implementation.
2020-04-14 11:30:11 -07:00
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