Commit Graph

15871 Commits

Author SHA1 Message Date
Pavel Yaskevich
5cacd1bb36 [ConstraintSystem] Fix situations when contextual base type can't be inferred
It might be either impossible to infer the base because there is
no contextual information e.g. `_ = .foo` or there is something
else wrong in the expression which disconnects member reference
from its context.
2019-12-03 12:07:16 -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
ac1ab1dfb0 [CSFix] Fix inability to infer contextual base type for member ref 2019-12-03 12:07:16 -08:00
Pavel Yaskevich
8b1debf907 [ConstraintSystem] Detect contextual type mismatches associated with optional evaluation 2019-12-03 12:07:16 -08:00
Pavel Yaskevich
918ff24767 [ConstraintSystem] Repair type mismatches between function types
If it couldn't be determined precisely what is the structural
difference between two function types, let's still repair the
mismatch by ignoring contextual type.
2019-12-03 12:07:16 -08:00
Pavel Yaskevich
ebdb5c7776 [ConstraintSystem] Improve handling of ambiguities related to fixes
Solutions passed to `diagnoseAmbiguityWithFixes` aren't filtered
so we need to remove all of the solutions with the score worse
than overall "best". Also logic has to account for some fixes being
"warnings".
2019-12-03 12:07:16 -08:00
Pavel Yaskevich
15c58d19d5 [ConstraintSystem] Detect passing array to variadic argument in function conversions
Initially this problem was only detected and diagnosed for calls.
So let's extend it to function conversions as well e.g.:

```swift
func foo<T>(_: [T]) {}
func bar<T>(_ f: (T...) -> ()) {}

bar { foo($0) }
```
2019-12-03 12:07:15 -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
Pavel Yaskevich
adf83fe9d5 [ConstraintSystem] Fix single tuple vs. N arguments in function conversions 2019-12-03 12:07:15 -08:00
Varun Gandhi
fb59293fe1 [Parse] Add a cType key to the convention attribute.
For example, one may write a calling convention like

  convention(c, cType: "void *(void)")

for a procedure that takes no arguments.
2019-12-02 21:06:01 -08:00
Slava Pestov
bbe9867d1f Merge pull request #28442 from slavapestov/revert-sf-synthesized-decls
Revert "Eagerly TypeCheck Synthesized Decls"
2019-12-02 21:37:15 -05:00
Slava Pestov
3aa70827e0 Merge pull request #28465 from zoecarver/feature/variadic-args-key-path-subscript
Fix variadic args in key path subscript
2019-12-02 21:35:53 -05:00
swift-ci
19395d6a4d Merge pull request #28446 from DougGregor/rdar57040259 2019-12-02 18:33:39 -08:00
Hamish Knight
2d7a088c91 Don't check access control for isCallableNominalType
We still want the constraint system to try looking up
a callAsFunction method even if it's inaccessible, as
we'll be able to record a fix and emit a suitable
diagnostic.
2019-12-02 15:29:22 -08:00
Hamish Knight
aa8d7ba833 [CS] Apply all finishApply's transforms to callAsFunction
Rather than coercing the call arguments ourselves,
just build the finished member reference for the
callAsFunction method, and let finishApply do the
rest. This allows us to deal with transformations
such as IUO unwraps.

Resolves SR-11881.
2019-12-02 15:29:21 -08:00
Hamish Knight
bf0e9c727d [CS] Resolve callees for implicit callAsFunction
Add a case to getCalleeLocator to return the
appropriate locator for a call to an implicit
callAsFunction member reference.

Resolves SR-11386 & SR-11778.
2019-12-02 15:29:21 -08:00
Hamish Knight
778e130f31 [Sema] Add TypeBase::isCallableNominalType
This checks whether a type supports being called
via callAsFunction. A request is used in order to
cache the result of this query.
2019-12-02 15:29:21 -08:00
swift-ci
8ac1f349a1 Merge pull request #22098 from DaveAMoore/SR-9738 2019-12-02 14:15:49 -08:00
Hamish Knight
19e199e567 Use DefaultArgumentExpr for caller-side defaults (#28279)
Use DefaultArgumentExpr for caller-side defaults
2019-12-02 13:57:17 -08:00
Owen Voorhees
badcc2c442 [Diagnostics] Don't include @unknown default in the empty switch fix-it (#28476) 2019-12-02 19:43:48 +00:00
Hamish Knight
53ed83c245 [CS] Coerce dynamic member strings to their param type (#28512)
[CS] Coerce dynamic member strings to their param type
2019-12-02 11:31:31 -08:00
swift-ci
926066af77 Merge pull request #28498 from hamishknight/warranty-void 2019-12-02 10:00:52 -08:00
Pavel Yaskevich
27db9f9f44 Merge pull request #28414 from xedin/cs-graph-printing
[ConstraintGraph] NFC: Adjustency list and equivalence class printing…
2019-12-02 09:57:57 -08:00
Pavel Yaskevich
95708bf230 Merge pull request #28421 from xedin/switch-dyn-keypath-to-interface-type
[TypeChecker] User interface type while validating keypath dynamic su…
2019-12-02 08:23:46 -08:00
Hamish Knight
e599c8b848 [CS] NFC: Remove unused variable 2019-11-30 14:47:29 -08:00
Hamish Knight
78bcb2e9ae [CS] Coerce dynamic member strings to their param type
Move `buildDynamicMemberLookupIndexExpr` into
ExprRewriter, and pass the string literal through
`handleStringLiteralExpr` to properly handle its
coercion to the parameter type.
2019-11-30 14:47:10 -08:00
Hamish Knight
7edbd9327e [CS] Remove an unused variable 2019-11-27 17:13:50 -08:00
Hamish Knight
a014f15e75 [CS] Enforce that withPathElement is called on an lvalue
Locator builders keep a pointer to their underlying
locator, so it's not generally sound to extend an
rvalue locator builder.

This commit enforces that withPathElement is called
on an lvalue, and adds a couple more overloads of
getConstraintLocator to make it more convenient to
extend locators with multiple elements.
2019-11-27 17:13:50 -08:00
David Moore
6a0d540949 Sema: Improve @dynamicCallable Diagnostics for Incorrect Parameter Types 2019-11-26 15:02:02 -05:00
zoecarver
c19f3cefec Remove silgen changes and use getParameterType in CSApply 2019-11-26 00:07:31 -08:00
zoecarver
d7f6e4a1b1 Cleanup 2019-11-23 21:50:34 -08:00
zoecarver
758bce9382 Fix variadic arguments in keypath subscripts 2019-11-23 21:43:13 -08:00
Pavel Yaskevich
dacdd13655 [ConstraintSystem] Propagate print options to type variable bindings store in solution 2019-11-22 16:43:09 -08:00
Pavel Yaskevich
86fa82d163 [ConstraintGraph] NFC: Adjustency list and equivalence class printing should respect printing flags 2019-11-22 16:26:35 -08:00
Doug Gregor
c4ed40dc15 [Type checker] Fix crash with invalid overriding property.
When an overriding property containing willSet or didSet is not within
a type, the type checker could crash due to a missing "self"
declaration. Check this condition. Fixes rdar://problem/57040259.
2019-11-22 15:38:05 -08:00
Slava Pestov
2cada3bce1 Revert "Eagerly TypeCheck Synthesized Decls"
This reverts commit cab4e9f011.
2019-11-22 17:41:34 -05:00
Varun Gandhi
99b72992ba [NFC] Add some useful crash information in CSApply. 2019-11-22 12:42:38 -08:00
Varun Gandhi
196f358dec [AST] Add ClangTypeConverter, computing C types for FunctionTypes.
Note: The change in ASTBuilder::createFunctionType is functionally minor,
but we need the FunctionType::Params computed _before_ the ExtInfo, so we
need to shuffle a bunch of code around.
2019-11-22 12:42:36 -08:00
Varun Gandhi
8021795672 [AST] Setup AST and SIL to accomodate Clang function types.
We still don't store compute or store the type anywhere; we will do so in
later commits.
2019-11-22 12:42:08 -08:00
Rintaro Ishizaki
83f9a52cb8 Merge pull request #28362 from owenv/improve_trailing_closure_in_condition_diag_2
[Parse] Reapply trailing closure in condition fix and downgrade to warning
2019-11-22 17:05:48 +09:00
Rintaro Ishizaki
ff34795107 [Sema] Use getResultInterfaceType() to get the result type
In `TypeCheckFunctionBodyUntilRequest`. So we can type check the body
without typechecking the signature.
2019-11-22 16:30:28 +09:00
Xi Ge
5a862e49bd Merge pull request #28369 from nkcsgexi/originally-defined-in-attribute
AST: introduce a new attribute @_originallyDefinedIn to the AST
2019-11-21 20:26:29 -08:00
Hamish Knight
bf1ed00e1f A few minor cleanups (#28427)
A few minor cleanups
2019-11-21 18:30:11 -08:00
Harlan Haskins
6f349036a9 Merge pull request #28425 from harlanhaskins/an-inconenient-init-parsing
[AST] Add attributes for hasMissingDesignatedInitializers and inheritsConvenienceInitializers
2019-11-21 17:28:09 -08:00
Xi Ge
aa1e4eec86 sema: check if @_originalDefinedIn attribute has duplicated entries for the same platform name 2019-11-21 17:04:00 -08:00
kelvin13
25e4cfc1a2 fix build failures 2019-11-21 18:47:50 -06:00
Hamish Knight
b0b68fc031 NFC: Remove an outdated comment 2019-11-21 16:21:57 -08:00
Hamish Knight
88b84c25b2 NFC: Remove an unnecessary use of NL_RemoveNonVisible
NL_QualifiedDefault already implies it.
2019-11-21 16:21:57 -08:00
Hamish Knight
2baeb3d36a NFC: Wrap a line to 80 column limit 2019-11-21 16:21:57 -08:00