Commit Graph

1092 Commits

Author SHA1 Message Date
Pavel Yaskevich
934351a8e3 [Diagnostics] Hint contextual type diagnostics with expression type if known
Avoid a re-typecheck in `diagnoseContextualConversionError` if the
expression type is already known and only return `true` if we know
that at least one error diagnostic has been emitted otherwise there
is a risk that type-check is going to return without any and fail
in verifier.

Resolves: rdar://problem/40002266
2018-05-12 13:56:53 -07:00
Pavel Yaskevich
7500c6eced [Diagnostics] Switch from vector to set to avoid storing duplicate solution types
This allows callees of `getPossibleTypesOfExpressionWithoutApplying`
to get only unique types from the re-run of the solver.
2018-05-12 11:28:34 -07:00
Huon Wilson
8e0bba14a0 Revert "[Diagnostics] Hint contextual type diagnostics with expression type if known" 2018-05-13 00:28:52 +10:00
Pavel Yaskevich
d102f7d590 [Diagnostics] Hint contextual type diagnostics with expression type if known
Avoid a re-typecheck in `diagnoseContextualConversionError` if the
expression type is already known and only return `true` if we know
that at least one error diagnostic has been emitted otherwise there
is a risk that type-check is going to return without any and fail
in verifier.

Resolves: rdar://problem/40002266
2018-05-11 13:50:36 -07:00
Pavel Yaskevich
52571eeffd [Diagnostics] Switch from vector to set to avoid storing duplicate solution types
This allows callees of `getPossibleTypesOfExpressionWithoutApplying`
to get only unique types from the re-run of the solver.
2018-05-11 13:50:11 -07:00
Anthony Latsis
d4fc337a9b Left string initialized empty
(for the further condition to work properly)
2018-05-08 16:54:01 +03:00
fischertony
1ec733cabb [Diagnostics] Provide fixits for cases with up to 10 missing closure args 2018-05-08 04:45:24 +03:00
Huon Wilson
d4fbca1183 [Sema/CS] std::function -> llvm::function_ref for some non-escaping params. 2018-05-01 08:29:08 +10:00
Anthony Latsis
96c0c13a2b [Diagnostics] SR-7445 Improve diagnostics for assignment failures (#16179)
* [Diagnostics] SR-7445 Improve diagnostics for assignment failures

* modified messages for assignments to function calls,
   modified messages for assignments to methods.
   removed comment for resolved radar.

* removed extra line and braces

* added tests for assignment_lhs_is_apply_expression
   eliminated redundant literal check which is always invoked before call
   reverted 'cannot assign to value' for literal assignments in subexpressions

* Complemented assigning to literal tests & reverted to 'cannot asign to value' for methods (was 'cannot assign to member')

* removed extra tabs

* eliminated one more accidental spacing

* Update CSDiag.cpp

* added highlighting, fixed & rechecked tests

* added highlighting for complex expressions involving assigning to literals

Resolves: [SR-7445](https://bugs.swift.org/browse/SR-7445)
2018-04-28 15:49:10 -07:00
Pavel Yaskevich
aa2b25b3dd Merge pull request #15868 from xedin/solver-get-params
[Sema] Attempt to replace usages of `getInput()` with `getParams()`
2018-04-26 23:32:15 -07:00
Pavel Yaskevich
3c64680a91 [Diagnostics] Switch CalleeCandidateInfo to use FunctionType::getParams() 2018-04-26 17:33:08 -07:00
Pavel Yaskevich
57ad592844 [Sema] Switch computeDefaultMap to use AnyFunctionType::getParams() 2018-04-26 17:33:08 -07:00
Slava Pestov
ff61b9e039 Sema: Fix another type variable leak with closures
When we type check a closure expression with inferred parameter
types, we assign type variables to them. If type checking fails,
we end up in FailureDiagnosis::diagnoseClosureExpr().

If there was no contextual type, we would skip the code path
which nukes type variables in the closure's ParamDecls before
proceeding to type check the body. Type checking of the body
creates a new constraint system which would pick up the outer
constraint system's type variables and blow up.

Fixes <rdar://problem/39489003>.
2018-04-25 20:52:34 -07:00
Pavel Yaskevich
0168fa43a4 Merge pull request #16056 from xedin/rdar-39514009
[Diagnostics] Check member name kind before trying to get its identifier
2018-04-20 18:03:21 -07:00
Huon Wilson
18683f305d Merge pull request #15587 from huonw/minmax
[Sema] Perform name lookup in outer scopes in some cases involving conditional conformances
2018-04-20 22:33:07 +10:00
Pavel Yaskevich
f036649fe6 [Diagnostics] Check member name kind before trying to get its identifier
Declarations with special names (e.g. (de-)init and subscript) don't have
identifiers so while trying to diagnose specific problems related to
members check if they have a kind appropriate to the situation.

Resolves: rdar://problem/39514009
2018-04-20 02:33:39 -07:00
Huon Wilson
0c53d44e53 [Sema] Consider outer max/min selection deprecated.
We warn and provide fixits, so that we're able restrict this behaviour to Swift
4 only by eagerly migrating people off of it.
2018-04-20 17:27:32 +10:00
Huon Wilson
9b68eb8a80 [AST] Allow unqualified name lookup to return results from outer scopes.
This is necessary for disambiguating calls to functions like `min` and
`max`.
2018-04-19 11:07:48 +10:00
Pavel Yaskevich
40b305e183 [Diagnostics] Switch to using FunctionType::getParams instead of input type
Convert all of the usages of `FunctionType->getInput()` to use
`Function->getParams()` instead which is a new preferred API.
2018-04-09 22:35:48 -07:00
John McCall
7815892a76 Add unique typo corrections to the main diagnostic with a fix-it.
Continue to emit notes for the candidates, but use different text.
Note that we can emit a typo correction fix-it even if there are
multiple candidates with the same name.

Also, disable typo correction in the migrator, since the operation
is quite expensive, the notes are never presented to the user, and
the fix-its can interfere with the migrator's own edits.

Our general guidance is that fix-its should be added on the main
diagnostic only when the fix-it is highly likely to be correct.
The exact threshold is debateable.  Typo correction is certainly
capable of making mistakes, but most of its edits are right, and
when it's wrong it's usually obviously wrong.  On balance, I think
this is the right thing to do.  For what it's worth, it's also
what we do in Clang.
2018-04-07 16:01:39 -04:00
Slava Pestov
a5579d1cff AST: Plug a hole in access control checking
A protocol extension of a private protocol can define internal
or public members. We should not be able to find these members
from another file or module if an internal or public type
conforms to the protocol.

Fixes <rdar://problem/21380336>.
2018-04-05 23:24:48 -07:00
Nathan Hawes
9200218122 Merge pull request #15688 from nathawes/rdar38149042-code-completion-hits-visitOpenExistentialExpr-unreachable
[CSGen][CSDiag] Update SanitizeExpr to sanitize OpenExistentialExpr
2018-04-04 13:56:23 -07:00
Sho Ikeda
4ba2303163 Merge pull request #15706 from ikesyo/sema-using-over-typedef
[gardening][Sema] Replace `typedef` with `using`
2018-04-04 19:34:13 +09:00
Mark Lacey
72f4b3d3b8 NFC: Minor cleanup to make createTypeVariable options default to zero.
Many (perhaps most?) calls to createTypeVariable explicitly pass 0 for
options. This change just defaults the parameter to 0 and removes all
the explicit 0's in the code.
2018-04-03 10:19:38 -07:00
Sho Ikeda
3c399de5bd [gardening][Sema] Replace typedef with using 2018-04-03 22:12:48 +09:00
Robert Widmann
788f65bdf0 Bail on nil literal diagnostics if the source is Optional 2018-04-03 01:51:59 -04:00
Nathan Hawes
136b5eff8b [CSGen][CSDiag] Update SanitizeExpr to santize OpenExistentialExpr
They can show up when re-typechecking via diag or code-completion and were
only being sanitized out in one place in CSDiag. Moved that logic into
SanitizeExpr.

Resolves rdar://problem/38149042
2018-04-02 11:42:09 -07:00
David Zarzycki
c8e17157af [Sema] Remove unneeded uses of TVO_CanBindToInOut 2018-03-28 14:25:13 -04:00
Robert Widmann
03580d2fe5 Add a parameter list to EnumElementDecl
This models, but does not plumb through, default arguments.
2018-03-28 00:05:56 -04:00
Pavel Yaskevich
5f222ec36d [Diagnostics] Improve diagnostics for type parameter requirements
Detect and diagnose failures in constraints representing
type parameter requirements generated by `openGeneric`.

Resolves: rdar://problem/35890334
2018-03-27 00:11:57 -07:00
Pavel Yaskevich
134f4e5611 [Diagnostics] Fix a crash when using withoutActuallyEscaping incorrectly
Teach `eraseOpenedExistentials` how to handle `OpaqueValueExpr`
associated with `MakeTemporarilyEscapableExpr`.

Resolves: rdar://problem/35773761
2018-03-23 14:41:30 -07:00
Slava Pestov
34fd4ae512 AST: Use DeclBaseName::Kind::Constructor
Fixes <rdar://problem/35852727>, <https://bugs.swift.org/browse/SR-1660>,
<https://bugs.swift.org/browse/SR-6557>.
2018-03-16 00:25:56 -07:00
Sho Ikeda
74ba135008 Merge pull request #15040 from ikesyo/gardening-not-empty
[gardening] Use `!empty()` over `size() > 0`
2018-03-08 18:47:12 +09:00
Huon Wilson
e307e54098 [AST] Explicitly track things marked __owned. 2018-03-08 12:36:24 +11:00
Sho Ikeda
cea6c03eb2 [gardening] Use !empty() over size() > 0 2018-03-08 09:21:09 +09:00
Sho Ikeda
26d650292f [gardening] Use empty() over size() == 0 2018-03-05 14:43:13 +09:00
Pavel Yaskevich
b7e322d877 [Diagnostics] Fix crash in diagnoseSubscriptErrors
If there is a single candidate with a valid index type, don't assume
that such candidate always has a valid function type. There are
multiple examples of this crash we've seen but there is no reproducer
test-case unfortunately.

Resolves: rdar://problem/37565861
2018-02-19 13:49:00 -08:00
Chris Lattner
a0fa5d11b4 Implement SE-0195, which introduces "Dynamic Member Lookup" Types (#14546)
* Implement the recently accepted SE-0195 proposal, which introduces "Dynamic
Member Lookup" Types.  This is a dusted off and updated version of PR13361,
which switches from DynamicMemberLookupProtocol to @dynamicMemberLookup as
was requested by the final review decision.  This also rebases it,
updates it for other changes in the compiler, fixes a bunch of bugs, and adds support for keypaths.  

Thank you to @rudx and @DougGregor in particular for the helpful review comments and test cases!
2018-02-16 16:19:50 -08:00
Pavel Yaskevich
8c17b925e6 [ConstraintSystem] Add TypeLoc caching to constraint system
This is useful for explicit casts and type expressions, where
type loc and expression types might be different, and allows
constraint solver to avoid setting opened types to expressions
which resolves multiple crashes.
2018-02-13 00:08:56 -08:00
Pavel Yaskevich
c0f5711ee5 [ConstraintSystem] Don't apply types to expressions until solution is found
Resolves: rdar://problem/36744895
2018-02-13 00:08:45 -08:00
Mark Lacey
be8defb29e Rename lookThroughAllAnyOptionalTypes to lookThroughAllOptionalTypes. 2018-02-05 23:59:01 -08:00
Mark Lacey
b4b66bc8e8 Replace getAnyOptionalObjectType with getOptionalObjectType. 2018-02-05 23:59:00 -08:00
Mark Lacey
3654dcc8fe Remove getImplicitlyUnwrappedOptionalObjectType. 2018-02-03 10:57:11 -08:00
Mark Lacey
3f9689e477 Remove lookThroughImplicitlyUnwrappedOptionalType. 2018-02-03 10:57:10 -08:00
Timur Islamgulov
56d1d6bbd3 Sema: Add a fix-it for integer literal to option set conversion. (#13899)
If expression type is IntegerLiteralExpr and value is equal to '0',
suggest '[]' as a replacement.

Resolves: rdar://problem/20704317 / SR-6716.
2018-01-12 13:34:49 -08:00
Pavel Yaskevich
ce847cc74b Merge pull request #13272 from chuganzy/SR-6272
[DiagnosticsQoI] SR-6272 Tailored diagnostics with fixits for numerical conversions
2018-01-12 01:06:18 -08:00
Mark Lacey
ad1dbac694 IUO: Create disjunctions for optional choices.
When binding an optional value, or function that returns an optional
value, if that value was produced from a decl that was declared an
IUO, create a disjunction.

After solving, make use of the disjunction choices in rewriting
expressions to force optionals where needed.

This is disabled for now, as it results in a source compatibility
issue without associated changes that actually start generating
Optional<T> in place of ImplicitlyUnwrappedOptional<T>. It's
complicated, but basically having two '??' (one returning T, one
returning T?) and creating a disjunction where the first (favored)
choice is ImplicitlyUnwrappedOptional<T> and second is T results in
our selecting the wrong '??' in some cases.
2018-01-08 14:31:03 -08:00
Slava Pestov
d843b10bcc Sema: Fix crash with unresolved dot expression with optional protocol metatype base
Mostly fixes <rdar://problem/35945827>, but there is a case that should
work that does not type check. At least we don't crash though.
2018-01-05 20:33:12 -08:00
Mark Lacey
41479f6334 IUO: Start creating the DeclForImplicitlyUnwrappedOptional OverloadChoice.
Use this in places where we have a decl that is marked with the
ImplicitlyUnwrappedOptionalAttr so that we can distinguish in the
solver which decls need to be potentially unwrapped in order to type
check successfully.
2018-01-04 14:00:36 -08:00
Mark Lacey
d1bb36425d IUO: Add overload choice kind for IUO decls.
Add a new OverloadChoiceKind for decls that are either IUO-typed, or
function-typed meaning that the function result type is IUO-typed.

Not currently used, so NFC.
2018-01-03 19:37:06 -08:00