Commit Graph

1092 Commits

Author SHA1 Message Date
Chris Lattner
778d8d67e6 Use isUnresolvedOrTypeVarType more generally, and fix a crash on the new testcase, handling
unresolved subscript bases.


Swift SVN r31698
2015-09-04 23:03:11 +00:00
Chris Lattner
34ae9bb9b6 Fix <rdar://problem/22584076> QoI: Using array literal init with dictionary produces bogus error
This includes a few changes:
 - Enhance diagnoseGeneralConversionFailure to not ignore constraints that are fully solved by
   CSDiags' heuristics.
 - Enhance dictionary/array literals diagnostics to handle non-compliance to their literal 
   protocols with a specific and custom error message.
 - Add specific QoI for turning accidental use of array literals in dictionary context into
   the right dictionary syntax (with a fixit).


Swift SVN r31696
2015-09-04 22:31:21 +00:00
Chris Willmore
a17ebe2f16 Add check to simplifyLocator for TupleElement.
When simplifying tuple element locator, be careful about possibly
accessing non-existent elements of TupleExpr anchor.

<rdar://problem/22426860> CrashTracer: [USER] swift at …mous_namespace::ConstraintGenerator::getTypeForPattern + 698

Swift SVN r31629
2015-09-02 08:50:59 +00:00
Chris Lattner
18ddc1ccdc change the "fail to resolve locator to expr" case in overload canddiate emission
give up instead of approximating an expr to complain about.  This sort of thing
causes the bizarre diagnostics that don't make sense, and it is better to generate
a more general ambituity error than something that doesn't make sense.  NFC since
diagnoseGeneralOverloadFailure is nearly dead anyway.



Swift SVN r31624
2015-09-02 06:06:28 +00:00
Chris Lattner
16a51639ef Fix <rdar://problem/22519983> QoI: Weird error when failing to infer archetype
Introduce a new "OpenedGeneric" locator for when openGeneric opens a generic
decl into a plethora of constraints, and use this in CSDiags to distinguish 
whether a constraint refers to an Expr as a whole or an "aspect" of the constraint.

Use that information in FailureDiagnosis::diagnoseGeneralConversionFailure
to know whether (as a fallback) we can correctly re-typecheck an entire expr 
to obtain a missing type.  If we are talking about an aspect of the expr, then
this clearly won't work.

The upshot of this is that where we previously compiled the testcase in 22519983
to:

y.swift:31:9: error: type '(inout _) -> Bool' does not conform to protocol 'RawRepresentable'
let a = safeAssign
        ^

we now produce the somewhat more useful:
y.swift:31:9: error: argument for generic parameter 'T' could not be inferred
let a = safeAssign
        ^
y.swift:27:6: note: in call to function 'safeAssign'
func safeAssign<T: RawRepresentable>(inout lhs: T) -> Bool {
     ^



Swift SVN r31620
2015-09-02 05:15:22 +00:00
Chris Lattner
c9fb58c662 remove the CheckedCastOperand & AddressOf locators which are no longer needed. NFC.
Swift SVN r31617
2015-09-02 04:19:54 +00:00
Chris Lattner
c26ed58541 remove IfThen/IfElse locators which are no longer needed.
Swift SVN r31616
2015-09-02 03:44:56 +00:00
Chris Lattner
be6da087d6 remove the AssignSource and AssignDest locators, which are no longer needed.
Swift SVN r31615
2015-09-02 03:40:55 +00:00
Chris Lattner
18107bf5c9 fix <rdar://problem/22298549> QoI: Unwanted trailing closure produces weird error
Swift SVN r31598
2015-09-01 04:56:06 +00:00
Chris Lattner
4ea7d1cd02 fix <rdar://problem/22491782> unhelpful error message from "throw nil"
Swift SVN r31593
2015-09-01 00:49:18 +00:00
Chris Lattner
bdb2edb198 With yaks properly groomed and infrastructure in place, we can now improve
diagnostics around invalid references to unavailable declarations, resolving
<rdar://problem/22491394> References to unavailable decls sometimes diagnosed as ambiguous

and a complex case exposed working through rdar://21928143.



Swift SVN r31587
2015-08-30 22:45:37 +00:00
Chris Lattner
379f5df269 Reimplement the diagnostics member resolution for SubscriptExprs to do a
member lookup for subscript instead of digging already-looked-up candidates 
out of the constraint system.  This allows us to produce more specific 
diagnostics in failure cases and keeps subscripts inline with other decls
being looked up.


Swift SVN r31586
2015-08-30 21:17:01 +00:00
Chris Lattner
1e5c13aa58 refactor the interface to performMemberLookup to pass in the components
of the constraint that it needs, not a constraint itself.  NFC.


Swift SVN r31585
2015-08-30 20:58:21 +00:00
Chris Lattner
b75517df2d fix the regressions on a few validation tests introduced by r31581.
Swift SVN r31584
2015-08-30 20:45:36 +00:00
Chris Lattner
02396d3a31 greatly simplify diagnoseGeneralOverloadFailure now that other stuff is carrying the
heavy weight of what it used to do, and make ambiguous subscript references produce
a more specific diagnostic.


Swift SVN r31581
2015-08-30 06:12:40 +00:00
Chris Lattner
8a8d8f14bf refactor some code so FailureDiagnosis::visitUnresolvedMemberExpr
can use the same logic to diagnose candidate failure as 
diagnoseGeneralMemberFailure.  Also, add a testcase for a diagnostic
we don't do a great job on.


Swift SVN r31579
2015-08-30 04:31:42 +00:00
Chris Lattner
9bb4825084 fix a merge issue which broke r31577
Swift SVN r31578
2015-08-30 03:47:16 +00:00
Chris Lattner
ceafc03074 make CSDiags more tolerant of a contextual unresolved type, fixing a
regression introduced by r31575


Swift SVN r31577
2015-08-30 03:05:37 +00:00
Chris Lattner
55628a97d2 Fix an overactive assertion: <rdar://problem/22470302> Crash with parenthesized call result
We type check expressions using a contextual purpose of CTP_CalleeResult
without a specific contextualType, because we install the contextual type
as a conversion constraint.  This formerly failed the assertion expecting
that you have to have a type if you have a purpose, because parenexprs 
propagated their contextual info down.

In addition to making the assertion in TypeCheckConstraints.cpp more
lenient, change visitCallExpr to just pass down the purpose directly
instead of installing it in its ExprTypeCheckListener.



Swift SVN r31575
2015-08-29 21:40:45 +00:00
Chris Lattner
1e4aa27407 fix <rdar://problem/22409190> QoI: Passing unsigned integer to ManagedBuffer elements.destroy()
... by remapping archetypes in partially resolved types down to 
unresolved type when providing contextual types.


Swift SVN r31522
2015-08-27 05:10:54 +00:00
Chris Lattner
d167dfbbfa When typechecking the callee of a CallExpr, and when we have a contextual type,
use that contextual type to guide typechecking of the callee.  This allows us to
propagate that type through generic constraints effectively, making us produce
much more useful diagnostics within closures taking methods like "map" (for 
example).

This fixes:
<rdar://problem/20491794> QoI closures: Error message does not tell me what the problem is
Specifically, running the testcase:

enum Color { case Unknown(description: String) }
let xs: (Int, Color) = [1,2].map({ ($0, .Unknown("")) })

produces: error: cannot convert call result type '[_]' to expected type '(Int, Color)'

Changing that to:
let xs: [(Int, Color)] = [1,2].map({ ($0, .Unknown("")) })

produces: error: missing argument label 'description:' in call
... with a fixit to introduce the label.

This also fixes most of 22333090, but we're only using this machinery for CallExprs
so far, not for operators yet.



Swift SVN r31484
2015-08-26 05:41:47 +00:00
Chris Lattner
1ce4511f14 add a TCC_ForceRecheck flag to typeCheckChildIndependently to factor handling
of the "isExprBeingDiagnosed" bit.  NFC.


Swift SVN r31482
2015-08-26 05:02:17 +00:00
Chris Lattner
a3048cf950 fix <rdar://problem/22414757> "UnresolvedDot" "in wrong phase" assertion from verifier
Swift SVN r31463
2015-08-26 00:01:47 +00:00
Chris Lattner
dd5489a9ad When diagnosing overload set candidates, pass the decl into diagnose
instead of the location of the decl.  This matters when the candidates
are coming from the stdlib because they have no location, and we can
synthesize a prototype from the decl.  Before we'd get:

t.swift:36:28: error: ambiguous reference to member 'String.init'
    return lazy.map(String.init).joinBySeparator(", ")
                    ~~~~~~~^~~~
<unknown>:0: note: found this candidate
<unknown>:0: note: found this candidate
<unknown>:0: note: found this candidate
.... 40 more of these.

Now we get:

t.swift:36:28: error: ambiguous reference to member 'String.init'
    return lazy.map(String.init).joinBySeparator(", ")
                    ~~~~~~~^~~~
Swift.String:95:3: note: found this candidate
  init()
  ^
Swift.String:96:3: note: found this candidate
  init(_ _core: _StringCore)
  ^
Swift.String:3:3: note: found this candidate
  init(_ c: Character)
  ^
Swift.String:24:3: note: found this candidate
  init(_ characters: String.CharacterView)
  ^
...



Swift SVN r31458
2015-08-25 23:12:54 +00:00
Chris Lattner
712d3447ce improve some diagnostics around inout expr.
Swift SVN r31415
2015-08-22 22:29:14 +00:00
Chris Lattner
d044bb3527 remove some special case code that is now not necessary, NFC.
Swift SVN r31413
2015-08-22 21:40:49 +00:00
Chris Lattner
76a26ae69c make ParenExpr handling more consistent, which is basically just a cleanup. This
wraps up 22102895


Swift SVN r31411
2015-08-22 21:09:11 +00:00
Chris Lattner
2c22cdc44c Teach CSDiag how to propagate contextual type information through TupleExpr,
one more step towards 20491794.



Swift SVN r31410
2015-08-22 20:35:41 +00:00
Chris Lattner
3a03435a1e Now that we have various infrastructure improvements in place, we can
remove some unprincipled code from typeCheckChildIndependently that was
special casing some expr nodes.


Swift SVN r31407
2015-08-22 06:06:14 +00:00
Chris Lattner
186fa8e9d6 Eliminate the TCC_AllowUnresolved flag by having typeCheckChildIndependently
automatically pass down TypeCheckExprFlags::AllowUnresolvedTypeVariables 
IFF we have no contextual type.  This gives us UnresolvedTypes in more cases,
which improves diagnostics in various situations, and also simplifies
CSDiag.  The change to misc_diagnostics.swift is a particularly nice progression.



Swift SVN r31406
2015-08-22 05:41:28 +00:00
Chris Lattner
b6de061dd6 Rework assignment diagnostics to be built in terms of contextual types,
where we type check the destination first, then apply its type to the source.

This allows us to get diagnostics for assignments that are as good as PBD
initializers and other cases.


Swift SVN r31404
2015-08-22 05:16:07 +00:00
Chris Lattner
b660cb3c8e Enhance the general parameter list matching logic in CSDiags to know about
argument list mismatches, and diagnose them with a very specific error when
they occur in member lookups.  This fixes
<rdar://problem/22356434> QoI: Missing diagnostic for invalid arguments passed to enum case constructor

where before we'd produce:

ee.swift:5:16: error: type of expression is ambiguous without more context
let list: E = .C(wrongLabel: 0)
              ~^~~~~~~~~~~~~~~~

now we produce:

ee.swift:1:17: error: incorrect argument label in call (have 'wrongLabel:', expected 'label:')
let list: E = .C(wrongLabel: 0)
                ^~~~~~~~~~~
                 label

I think that unresolved member exprs now get good diagnostics in all cases that they have
a contextual type, but of course there are lots more cases where we're not getting a 
contextual type.



Swift SVN r31402
2015-08-22 04:46:49 +00:00
Chris Lattner
cd7d638a0b refactor "evaluateCloseness" and related machinery to be defined in terms of
an array of TupleTypeElt's instead of an array of Type's, exposing information
about varargs and parameter labels to it.  NFC.


Swift SVN r31385
2015-08-21 18:19:23 +00:00
Chris Lattner
8f0d0d325d build out the infrastructure for diagnosing calls that have contextual type
information and use this to improve the UnresolvedMemberExpr errors.

The notable problem remaining is that we don't handle problems involving
argument labels.


Swift SVN r31378
2015-08-21 05:24:00 +00:00
Chris Lattner
6358c3049d Now that we consistently propagate contextual type information when it
is available, use it to start producing useful diagnostics for contextually
typed member references.


Swift SVN r31362
2015-08-20 17:07:15 +00:00
Chris Lattner
61de97b063 Switch string literal type checking to work more like other literals: if
it already has a type, don't re-type-check the literal.  This improves a
diagnostic involved with 20491794.


Swift SVN r31330
2015-08-19 04:58:36 +00:00
Chris Lattner
458534f9d7 fix <rdar://problem/22320758> QoI: collection literals don't handle substitutions well in csdiag
Now we can propagate contextual types through collection literals even when they are generic, producing
specific diagnostics for elements within them.


Swift SVN r31327
2015-08-19 04:24:27 +00:00
Chris Lattner
7dcb4e7b71 remove some redundant code Slava noticed
Swift SVN r31324
2015-08-19 00:50:56 +00:00
Chris Lattner
f72b2136c4 simplify and rebrand diag::invalid_relation now that it can only produce
two messages.


Swift SVN r31320
2015-08-18 23:58:49 +00:00
Chris Lattner
248727780f Now that enough yaks are cleanly shaven, completely reimplement how
we process contextual constraints when producing diagnostic.  Formerly,
we would aggressively drop contextual type information on the floor under
the idea that it would reduce constraints on the system and make it more
likely to be solvable.  However, this also has the downside of introducing
ambiguity into the system, and some expr nodes (notably closures) cannot
usually be solved without that contextual information.

In the new model, expr diagnostics are expected to handle the fact that
contextual information may be present, and bail out without diagnosing an
error if that is the case.  This gets us more information into closures,
allowing more specific return type information, e.g. in the case in
test/expr/closure/closures.swift.

This approach also produces more correct diagnostics in a bunch of other
cases as well, e.g.:

-  var c = [:]  // expected-error {{type '[_ : _]' does not conform to protocol 'DictionaryLiteralConvertible'}} 
+  var c = [:]  // expected-error {{expression type '[_ : _]' is ambiguous without more context}}

and the examples in test/stmt/foreach.swift, test/expr/cast/as_coerce.swift,
test/expr/cast/array_iteration.swift, etc.

That said, this another two steps forward, one back thing.  Because we
don't handle propagating sametype constraints from results of calls to their
arguments, we regress a couple of (admittedly weird) cases.  This is now 
tracked by:
<rdar://problem/22333090> QoI: Propagate contextual information in a call to operands

There is also the one-off narrow case tracked by:
<rdar://problem/22333281> QoI: improve diagnostic when contextual type of closure disagrees with arguments



Swift SVN r31319
2015-08-18 23:55:02 +00:00
Chris Lattner
b9e97ed600 Fix the constraint ranking predicate to produce a correct partial ordering w.r.t to
favored bit.  Also, ignore disjunction constraints now that we drop them on the floor
here.

Also, move the in_cast_expr_types blob down further, to make sure we emit the note for
a diagnostic after the error.

NFC on the testsuite.


Swift SVN r31312
2015-08-18 22:02:47 +00:00
Chris Lattner
4f15bce57a refactor a bit of the code filtering UnresolvedTypes, NFC.
Swift SVN r31306
2015-08-18 19:21:59 +00:00
Chris Lattner
880f06aedf Enhance FailureDiagnosis::diagnoseGeneralOverloadFailure to more correctly
handle try/try? exprs between the overload set and the CallExpr (previously
we'd blow by the CallExpr walking the parent map) and make some other 
diagnostic generation stuff more careful about handling type variables.

NFC since type vars aren't getting into here yet.



Swift SVN r31301
2015-08-18 18:21:58 +00:00
Chris Lattner
045c4533c1 remove a now-redundant flag, which is implicit in typeCheckArbitrarySubExprIndependently.
Swift SVN r31300
2015-08-18 18:02:29 +00:00
Chris Lattner
505ff58cdb Make conversion diagnostics between as? and as! expression consistent by allowing
diagnoseGeneralConversionFailure() to handle them (instead of it handling as? but
special code handling as!).

As part of this, enhance things so we get error messages about both the problem, 
and the overall type involved (when they're different) e.g.:

  if let s = setD as? Set<BridgedToObjC> { }

error: 'ObjC' is not a subtype of 'DerivesObjC'
note: in cast from type 'Set<DerivesObjC>' to 'Set<BridgedToObjC>'

This also finally fixes the case in test/Generics/existential_restrictions.swift



Swift SVN r31299
2015-08-18 18:00:37 +00:00
Chris Lattner
fa6dcfee50 rework how diagnoseConstraintFailure sorts through constraints that it
is considering, making it a bit stronger at handling disjunction constraints
as well as fixing it to stop sending non-conversion constraints down into
diagnoseGeneralConversionFailure.



Swift SVN r31294
2015-08-18 17:12:46 +00:00
Chris Lattner
8e758ba19f Make the "type of expression is ambiguous without more context" diagnostic more
specific when it fails, by printing a potentially partially resolved type for the
ambiguous expression in question, which it carries information.  This can at least
tell what the ambiguous parts of the resultant type *are* in some cases (e.g. in
the Constraints/array_literal.swift case).  That said, this diagnostic is still
admittedly not great.

This also exposes a couple of cases where we produce bogus diagnostics in general 
(expr/cast/as_coerce.swift).  The issue here is that these shouldn't be ambiguous 
at all, they are being misreported due to 22320758), which I'll fix separately.



Swift SVN r31292
2015-08-18 06:05:46 +00:00
Chris Lattner
c34fb19a92 fix a regression on Swift.compiler_crashers_fixed.26134-swift-constraints-constraintsystem-solverstate-solverstate.swift
Swift SVN r31291
2015-08-18 05:06:26 +00:00
Chris Lattner
1ad24fdfc2 rework how 'as' casts are diagnosed, removing a special case from CSApply and
allowing these failures to hook into other diagnostic goodies (e.g. the
"did you mean to use '!' or '?'?" cases showing in the testsuite).  That said,
by itself this doesn't have a huge impact, but avoids regressions with other
pending changes.


Swift SVN r31289
2015-08-18 04:35:41 +00:00
Chris Willmore
8c57b7cde5 Improve diagnosis of implicit match expressions
When diagnosing failure to typecheck a binary '~=' expression that was
synthesized when typechecking an expression pattern, offer a message
that describes the failure more helpfully.

<rdar://problem/21995744> QoI: Binary operator '~=' cannot be applied to operands of type 'String' and 'String?'

Swift SVN r31286
2015-08-18 02:33:10 +00:00