Commit Graph

1357 Commits

Author SHA1 Message Date
Jordan Rose
b318ab125d Prefer RawRepresentable fix-its that don't require an extra conversion
That is, if a type has a raw value of Int, and the function being
called has overloads for both Int and UInt, we always want to offer a
fix-it that leads to the 'Int' overload, not insert a conversion to
UInt that might be incorrect.

More https://bugs.swift.org/browse/SR-8150.
2018-07-03 13:24:36 -07:00
Jordan Rose
cc82ae00d9 Fix RawRepresentable fix-its for single unlabeled arguments
They were being put outside the call parentheses instead of inside.
We even had tests for this; I just got them wrong.

https://bugs.swift.org/browse/SR-8150
2018-07-03 13:24:22 -07:00
Doug Gregor
80688d0176 [Type Checker] Remove the TypeChecker from most of the “override” checking.
A type checker instance isn’t needed for most of the “override” checking,
so remove the TypeChecker parameters and instead get the ASTContext or
DiagnosticEngine from whatever decl or type is available. Another step
toward reducing dependency on a TypeChecker instance.
2018-07-02 23:00:39 -07:00
Doug Gregor
d098b3e571 [Sema] Remove the IterativeTypeChecker. 2018-06-15 22:46:55 -07:00
Doug Gregor
18569e5f77 Merge pull request #16963 from DougGregor/evaluator-type-checker
[Type checker] Use the request-evaluator in the type checker.
2018-06-15 22:41:31 -07:00
Matt Diephouse
87aaf10e6b [Diagnostics] Improve error when type parameters aren't equal 2018-06-15 15:08:05 -04:00
Doug Gregor
b7fbe57bf9 [AST] Remove “validated” bit from TypeLoc.
TypeLocs have been “validated” when they have a non-null Type, so eliminate
the separate “validated” bit that was out-of-sync with the Type field.
2018-06-14 15:29:57 -07:00
Matt Diephouse
863d7d36f2 [Diagnostics]: Rewrite "no subscript members" error
• Change name to match names of member diagnostics.

• Explicitly call out that this is a "value of type". This matches the error from non-existent methods and properties.

• Don't call them "subscript members". That term is never used in documentation and "member" doesn't add anything besides confusion.
2018-06-13 13:35:24 -04:00
Slava Pestov
51319ee171 Merge pull request #17106 from AnthonyLatsis/clean_subscript_fixits_logic
[CSDiag] Remove nested type and use TC.isConvertible instead
2018-06-11 21:43:00 -07:00
fischertony
88928a8eba [CSDiag] Remove nested type and use TC.isConvertible instead 2018-06-11 14:10:44 +03:00
Robert Widmann
24abf3ea09 [NFC] Refactor default argument info
Refactor the interface to return a bit vector. Along the way, fix up
the callers and remove some dead usages of the defaults information
that were copied and pasted around Sema.
2018-05-31 17:28:04 -07:00
Robert Widmann
7e8aa9fcc6 [NFC] Rename @lvalue Locator Path Element
8271c1a removed the last hacky usage of ArrayElementType,
leaving behind just the @lvalue-to-inout conversions.  Rename
the locator path element to reflect this and do a bit of cleanup on the
unrelated-but-near-enough other hack RValueAdjustment.
2018-05-26 16:48:41 -07:00
fischertony
dcf75de693 [#16431][Amendments] Note emitting amendment & use generic note
Show the note always if there is a single candidate
Switch to using the generic 'declared here' diag introduced in #16766
2018-05-24 17:24:39 +03:00
Anthony Latsis
7139152132 [Diagnostics|SR-5789] Fixits for applying subscripts by keyword (#16431)
* [Diagnostics|SR-5789] Added fixits for referring to subscripts by keyword

If there is a subscript member, the error message changes to [type -bash has no member property or method named 'subscript']
The fix-it replaces parentheses with brackets, removes '.subscript'
If the apply expression is incomplete, e.g. subscript(..., the fix-it adds a bracket at the end.

* tests updated & logic for compatible arg types (except generics)

* ignore generic types & switch to returning

* avoid explicitly using sting literals

* handle implicit conversion of tuples & encapsulate it

* isolate subscript misusage

* return bool instead of void

* move function to FailureDiagnosis, diagnose independently & update error message

* Update CSDiag.cpp
2018-05-22 11:18:27 -07:00
Mark Lacey
43775e817d Disallow some implicit pointer conversions in autoclosures.
Disallow implicit conversion or arguments from Array, String, and
InOut (formed by &) to pointer types if the argument is for an
@autoclosure parameter.

These conversions were really only intended to be used for C/ObjC
interop, and in some contexts like autoclosures they are not safe.

Fixes: rdar://problem/31538995
2018-05-16 12:13:25 -07:00
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