Commit Graph

885 Commits

Author SHA1 Message Date
Slava Pestov
241abfaaee Merge pull request #5869 from jtbandes/diag-inaccessible-init
[QoI] Improve diagnostics when accessing .init on a non-metatype
2016-11-23 18:25:36 -05:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
Jacob Bandes-Storch
2fd3aa157a [QoI] Improve diagnostics when all .init candidates are inaccessible 2016-11-19 01:19:27 -08:00
Mark Lacey
a4a6c0d5e0 Clean-up solver state management for a constraint system.
Make SolverState manage whether the ConstraintSystem it belongs to has a
current SolverState.

Also a couple minor formatting fixes for ternary expressions involving
solverState.
2016-11-15 17:06:20 -08:00
Doug Gregor
6bfd219e14 [AST] Separate GenericEnvironment's representation from its interface. 2016-11-14 21:44:58 -08:00
Doug Gregor
e045429471 [Type Checker] Improve interface to TypeChecker::conformsToProtocol().
This function had a weird, pre-ProtocolConformanceRef interface that
returned true when the type conformed to the protocol, then had a
separate indirect return value for the concrete conformance (if there
is one). Refactor this API, and the similar
TypeChecker::containsProtocol(), to produce an optional
ProtocolConformanceRef, which is far more idiomatic and easier to
use. Push ProtocolConformanceRef into a few more places. Should be NFC
2016-11-14 16:00:58 -08:00
Rintaro Ishizaki
903242c5fa [Diag] Don't use typed editor placeholder in diagnostics.
Most of command line users are not familiar with <#T##TypeName#> syntax.
2016-11-12 05:00:36 +09:00
Rintaro Ishizaki
5adc3bf804 [QoI] Add fix-it for missing arguments 2016-11-12 04:29:52 +09:00
Doug Gregor
08aa31d519 [Constraint solver] Slightly expand the "contextual conversion failure" check.
Expand the context conversion failure check used to fix
rdar://28909024 to cover the case where we have a single-argument
mismatch and there is a type parameter deduction as well.
2016-11-08 16:11:30 -08:00
Doug Gregor
e20464a02c [Constraint solver] Remove 'type member' constraint.
Only some fallback code in the for-each binding checking code was
using this constraint. Implement those checks more directly.
2016-11-06 23:14:15 -08:00
Pavel Yaskevich
92b19fdb42 [Diagnostics] SR-2164: Fix erroneous diagnostic when unable to infer generic parameter
When trying to diagnose ambigiuty with constraint system check if any of the
unresolved type variables are related to generic parameters, and if so
try to diagnose a problem based on the number of constraints associated with
each of the unresolved generic parameters.

Number of constraints related to a particular generic parameter
is significant indicator of the problem, because if there are
no constraints associated with it, that means it can't ever be resolved,
such helps to diagnose situations like: struct S<A, B> { init(_ a: A) {}}
because type B would have no constraints associated with it.
2016-11-01 14:57:14 -07:00
swift-ci
3fc5aef425 Merge pull request #5545 from xedin/r28909024 2016-10-31 10:44:01 -07:00
Pavel Yaskevich
02cae22541 [Diagnostics] Extend contextual failure checking to all apply expressions
As an extension of SR-2208 apply contextual conversion failure checking
to all of the expressions diagnosed via FailureDiagnosis::visitApplyExpr.

Resolves <rdar://problem/28909024>.
2016-10-30 22:28:26 -07:00
Alex Hoppen
b0e67da844 [TypeChecker] Add error message when accessing a type's destructor
Provide error messages when the destructor is accessed using foo.deinit
instead of crashing

This resolves SR-2652 and SR-3043
2016-10-30 19:43:57 +00:00
practicalswift
59a2b28239 [gardening] Fix recently introduced typos. 2016-10-28 22:28:55 +02:00
Pavel Yaskevich
dd01b7e184 [Diagnostics] SR-2208: Improve failure diagnostics for apply expressions 2016-10-26 14:34:05 -07:00
Rintaro Ishizaki
31245aaa1a [Sema] Check hasResult() before getResult() from ReturnStmt (#5362)
Fixes compiler_crashers/28390-swift-expr-walk.swift
2016-10-20 08:18:36 +09:00
Mark Lacey
f72576d03c Merge pull request #5237 from xedin/SR-2484
SR-2484: Improve diagnostic for incorrectly called private init
2016-10-17 18:37:08 -07:00
Pavel Yaskevich
352f4b7f73 [Diagnostics] SR-2484: Improve diagnostic for incorrectly called private init 2016-10-15 02:35:27 -07:00
Mark Lacey
32634b1bdd Merge pull request #5239 from xedin/SR-1255
SR-1255: Improve diagnostic when one of the parameters marked as autoclosure
2016-10-14 12:40:21 -07:00
Doug Gregor
49b833b51a [Type checker] Eliminate the 'literalConformanceProto' state on type variables.
The 'literalConformanceProto' field of
TypeVariableType::Implementation didn't take into account equivalence
classes of type variables. Eliminate it, and either look at the actual
expressions (for optimizing constraints during constraint generation)
or the actual constraints on a given type variable (for determining
whether to include optionals in the set of potential type variable
bindings).

(cherry picked from commit 6bdd9cfae5)
2016-10-13 16:22:01 -07:00
Doug Gregor
01fa24cc9b Speculatively revert "[Type checker] Eliminate the 'literalConformanceProto' state on type variables."
This reverts commit 6bdd9cfae5. This
commit *appears* to be breaking something in Dollar involving
inference with array literals and 'nil'; pull it back for more
investigation.
2016-10-12 09:20:16 -07:00
Robert Widmann
f59d5cb577 Normalize the way paren types are stripped in Sema. 2016-10-12 00:00:39 -04:00
Doug Gregor
6bdd9cfae5 [Type checker] Eliminate the 'literalConformanceProto' state on type variables.
The 'literalConformanceProto' field of
TypeVariableType::Implementation didn't take into account equivalence
classes of type variables. Eliminate it, and either look at the actual
expressions (for optimizing constraints during constraint generation)
or the actual constraints on a given type variable (for determining
whether to include optionals in the set of potential type variable
bindings).
2016-10-11 17:09:13 -07:00
Doug Gregor
c2b9759cd3 Simplify ConstraintSystem::getFixedTypeRecursive and use it consistently.
We had a few places that were performing ad hoc variants of
ConstraintSystem::getFixedTypeRecursive(); simplify it's interface so
we can use it everywhere consistently. Fixes rdar://problem/27261929.
2016-10-11 17:08:52 -07:00
Pavel Yaskevich
f526a251c6 [Diagnostics] SR-1255: Improve diagnostic when one of the parameters marked as autoclosure 2016-10-11 14:43:37 -07:00
Doug Gregor
ab959c9f21 Introduce TypeBase::isTypeVariableOrMember(). NFC
Similar to “isTypeParameter,” this new entry point determines whether the type is a type variable or a nested type of a type thereof. The latter case isn’t actually formed yet, so this is NFC staging the trivial bits of this change.
2016-10-11 11:38:52 -07:00
swift-ci
d38198bd68 Merge pull request #5063 from graydon/rdar-27982012-poor-diagnostic 2016-10-07 17:56:00 -07:00
Doug Gregor
50341da32b Use "TypeBase::hasError()" rather than "is<ErrorType>()" where needed.
In most places where we were checking "is<ErrorType>()", we now mean
"any error occurred". The few exceptions are in associated type
inference, code completion, and expression diagnostics, where we might
still work with partial errors.
2016-10-07 10:58:23 -07:00
Graydon Hoare
0d5420b7dd In CSDiag, diagnose callee inaccessibility before digging into args.
Fixes QoI rdar://problem/27982012
2016-10-07 09:35:03 -07:00
Slava Pestov
354416f912 AST: Kill Type::getAllGenericArgs()
This was almost identical to getMemberSubstitutions(), except
protocol and protocol extension members are not properly
supported.

Now that this method is no longer used by the ASTPrinter, there
are only two remaining usages, both trivially refactorable to
use better APIs.
2016-10-03 00:39:49 -04:00
Rintaro Ishizaki
65f3ba5dbb [Sema] Unify fix-it logic for enclosing trailing closure in argument parens (#4961)
`tryDiagnoseTrailingClosureAmbiguity` and `checkStmtConditionTrailingClosure`
had similar logic.
Added swift::fixItEncloseTrailingClosure function.
2016-09-24 18:33:40 +09:00
Pavel Yaskevich
054e3e4eb4 [Diagnostics] SR-2242: Fix diagnostic when argument label is omitted 2016-09-23 17:17:59 -07:00
Pavel Yaskevich
2dfc8b60ad [Diagnostics] Refactor argument source range retrieval 2016-09-23 15:14:21 -07:00
Pavel Yaskevich
f0078d6bc3 [Diagnostics] Refactor argument matching when dealing with a single candidate 2016-09-23 15:14:21 -07:00
Slava Pestov
a9c68c0736 AST: Remove archetype from AbstractTypeParamDecl
There's a bit of a hack to deal with generic typealiases, but
overall this makes things more logical.

This is the last big refactoring before we can allow constrained
extensions to make generic parameters concrete. All that remains
is a small set of changes to SIL type lowering, and retooling
some diagnostics in Sema.
2016-09-22 19:48:30 -07:00
swift-ci
675e542f3b Merge pull request #4939 from rudkx/fix-27830834 2016-09-22 18:02:09 -07:00
Jordan Rose
b9e1d4c21c Don't use construction to convert literals in rawValue fix-it. (#4934)
Input:  panel.styleMask = 8345
Old output:  panel.styleMask = NSWindowStyleMask(rawValue: UInt(8345))
New output:  panel.styleMask = NSWindowStyleMask(rawValue: 8345)

rdar://problem/26681232
2016-09-22 17:36:41 -07:00
Mark Lacey
b44a93ea84 Fix crash on typecheck failure in interpolated strings.
We were attempting to clean up stray type variables before creating a
new constraint system and moving forward with narrowing down the
typecheck failure, but we were failing to remove type variables for
interpolated strings.

Fix that, as well as removing them from TypeExpr's, and add an assert
that on exit from the pre-order visitor we don't have any type
variables (except for literals that aren't interpolated strings, which
I'm going to dig into further).

Fixes rdar://problem/27830834 and SR-2716.
2016-09-22 17:09:31 -07:00
Michael Ilseman
4324d8f4b0 [CSDiag] Switch to using the ASPrinter rather than repeating logic 2016-09-22 13:19:22 -07:00
Jordan Rose
821cdf368d Merge pull request #4910 from jrose-apple/fix-it-swift_newtype-rawValue
Use the existing '.rawValue' fix-it to handle unwrapping objects too.

rdar://problem/26678862
2016-09-21 18:28:40 -07:00
Jordan Rose
693fd9d455 Use the existing '.rawValue' fix-it to handle unwrapping objects too.
We could probably make this even more general, but this specifically
avoids trying to insert an "as AnyObject" fix-it, which will now work
but probably produce an incorrect result. This comes up when working
with swift_newtype wrappers of CF types being passed to CFTypeRef
parameters.

rdar://problem/26678862
2016-09-21 17:16:26 -07:00
Jordan Rose
caeed32302 Add a fix-it for missing generic parameters on construction.
For example, if someone tries to use the newly-generic type Cache,
from Foundation:

  var cache = Cache()

they'll now get a fix-it to substitute the default generic parameters:

  var cache = Cache<AnyObject, AnyObject>()

The rules for choosing this placeholder type are based on constraints
and won't be right 100% of the time, but they should be reasonable.
(In particular, constraints on associated types are ignored.)
In cases where there's no one concrete type that will work, an Xcode-
style placeholder is inserted instead.

- An unconstrained generic parameter defaults to 'Any'.
- A superclass-constrained parameter defaults to that class,
  e.g. 'UIView'.
- A parameter constrained to a single @objc protocol (or to AnyObject)
  defaults to that protocol, e.g. 'NSCoding'.
- Anything else gets a placeholder using the generic parameter's name
  and protocol composition syntax.

rdar://problem/27087345
2016-09-21 18:04:14 -06:00
Jordan Rose
6bc61fe8ce Fix a fix-it to cast to the destination type, not the source type.
Copy/paste issue, most likely.
2016-09-21 16:40:40 -07:00
Slava Pestov
ced715cb46 Sema: Fix crash when attempting to diagnose a contextual conversion of an ambiguous expression
The fixits call back into the type checker via typeCheckCheckedCast(),
which sets up a new constraint system. As a result we would hit
assertions by introducing type variables from a previous "generation".

It seems that if we bail out of this code path altogether, we get a
better diagnostic -- in the provided test, it complains about an
ambiguous member to '.value', rather than not being able to convert
_? to V?.

Fixes <https://bugs.swift.org/browse/SR-2592>.
2016-09-19 17:53:05 -07:00
Jordan Rose
e6d6e0e92f Offer fix-its to disambiguate based on a trailing closure's label.
(by making it a normal argument with a label and not a trailing
closure)

Diagnostic part of rdar://problem/25607552. A later commit will keep
us from getting in this situation quite so much when default arguments
are involved.
2016-09-15 11:05:02 -07:00
Jordan Rose
a14e3291ce Say "ambiguous use of 'foo'" instead of "'foo(bar:)'".
...unless the argument labels are the same for every possible
overload.

Only affects diagnostics.
2016-09-15 10:38:44 -07:00
Jacob Bandes-Storch
bc3a7d1241 [QoI] improve diagnostics for contextual members with argument mismatch 2016-08-28 15:59:41 -07:00
Andrew Trick
580372b98b [diagnostics] Emit a a note for optional conversion of raw pointers. (#4442)
In CSDiag.cpp I previously added a helper, isCastToTypedPointer(), to emit an
diagnostics explaining how to migrate UnsafeRawPointer conversion. This commit
broadens that diagnostic to handle Optional<UnsafeRawPointer>.

rdar:27894255 [3.0 migration] Emit an additional note for conversion
2016-08-20 21:11:50 -07:00
Slava Pestov
8a67d71de0 Sema: Look through TryExpr in FailureDiagnosis
This fixes a case where we would produce the generic 'ambiguous without
more context' error when a 'try' was present.

Fixes <rdar://problem/27891805>.
2016-08-19 16:01:38 -07:00