Commit Graph

1334 Commits

Author SHA1 Message Date
Chris Willmore
da15fbf4ce [Sema] Error on generic arg lists with different lengths
Don't assert that generic arg lists have the same lengths. We don't
currently allow nested generics, but we try to type-check anyway, and
one of the effects is sticking the generic params for both the outer and
inner classes on the inner type. Instead, just error out.

<rdar://problem/21967211>
2015-11-10 18:08:29 -08:00
Chris Willmore
a79c1c9bf4 Don't allow conversion from inout argument to Any parameter.
<rdar://problem/23249098>
2015-11-03 19:00:46 -08:00
Doug Gregor
2d5d3d240c Omit needless words: use the actual mapped names for builtin C types.
This provides better fidelity between omit-needless-words acting on
Clang types vs. acting on Swift types.

Swift SVN r32383
2015-10-01 22:37:40 +00:00
Chris Willmore
49e5130103 Allow inout closure param type to be inferred from context or usage.
Introduce a new constraint kind, BindParam, which relates the type of a
function parameter to the type of a reference to it from within the
function body. If the param type is an inout type, the ref type is an
lvalue type with the same underlying object type; otherwise the two
types must be the same. This prevents DeclRefExprs from being inferred
to have inout type in some cases.

<rdar://problem/15998821> Fail to infer types for closure that takes an inout argument

Swift SVN r32183
2015-09-23 18:46:12 +00:00
Chris Lattner
f8c6e46e03 remove the Failure::IsNotOptional failure mode, as CSDiags does a better job
of providing contextual diagnostics (e.g. producing the warning in 
Constraints/dynamic_lookup.swift).  This drops a specific diagnostic about
force casting the result of as! which was added in the Swift 1.2 timeframe
to explain the change in cast semantics.  Now that as! has been around for
a long time, it is more confusing than helpful.



Swift SVN r31887
2015-09-11 04:40:13 +00:00
Chris Lattner
72c5c3e4fe Two changes:
- Enhance the branch new argument label overload diagnostic to just
   print the argument labels that are the problem, instead of printing
   the types inferred at the argument context.  This can lead to confusion
   particularly when an argument label is missing.  For example before:

error: argument labels '(Int)' do not match any available overloads
note: overloads for 'TestOverloadSets.init' exist with these partially matching parameter lists: (a: Z0), (value: Int), (value: Double)

after:

error: argument labels '(_:)' do not match any available overloads
note: overloads for 'TestOverloadSets.init' exist with these partially matching parameter lists: (a: Z0), (value: Int), (value: Double)


Second, fix <rdar://problem/22451001> QoI: incorrect diagnostic when argument to print has the wrong type
by specifically diagnosing the problem when you pass in an argument to a nullary function.  Before:

error: cannot convert value of type 'Int' to expected argument type '()'

after:
error: argument passed to call that takes no arguments
print(r22451001(5))
                ^




Swift SVN r31795
2015-09-09 00:26:37 +00:00
Chris Lattner
ce7bcc3bea One second thought: keep the interface to computeTupleShuffle consistent:
change its implementation to take a list of TupleTypeElt for both the
from/to tuple type, but provider a convenience wrapper that takes the
from/to tuple type as TupleType's.


Swift SVN r31733
2015-09-06 22:23:25 +00:00
Chris Lattner
17c3ebbd49 remove a function that is dead after r31728
Swift SVN r31732
2015-09-06 22:17:45 +00:00
Chris Lattner
21acbd42a0 refactor constraints::computeTupleShuffle() to take its first tuple as
an exploded list of elements, which is more convenient for at least one
caller.  NFC.



Swift SVN r31731
2015-09-06 22:17:22 +00:00
Chris Lattner
bab9b62c87 reimplement the "function produces expected type 'XYZ'; did you mean to call it with '()'?"
fixit hint in CSDiags instead of being a FixKind.  This resolves a number of issues with
it, particularly that it didn't actually check to see if the function in question takes
a () argument or not.  

This fixes:
<rdar://problem/21692808> QoI: Incorrect 'add ()' fixit with trailing closure

among other issues.



Swift SVN r31728
2015-09-06 20:41:21 +00:00
Chris Lattner
9f01aa2b3f revert the fix to rdar://22298549, it is causing a crash on the
testcase in rdar://21692808


Swift SVN r31727
2015-09-06 20:18:25 +00:00
Chris Lattner
44b35a85f8 remove a bunch more Failure conditions that CSDiags ignores.
Swift SVN r31718
2015-09-05 21:53:08 +00:00
Chris Lattner
86b47b8186 remove the TupleSizeMismatch failure mode and diagnose the problem in the mainline
expr diagnosis stuff, giving us much better diagnostics on the cases in
expr/closure/closures.swift.  This is part #2 of resolving
<rdar://problem/22333281> QoI: improve diagnostic when contextual type of closure disagrees with arguments



Swift SVN r31717
2015-09-05 21:38:06 +00:00
Chris Lattner
877fa0bf84 remove some dead "Failure" cases that CSDiags already ignores because it handles them
better in its expression-driven system.


Swift SVN r31716
2015-09-05 21:09:02 +00:00
Chris Lattner
659dde32ab simplify some code, NFC.
Swift SVN r31619
2015-09-02 05:11:56 +00:00
Chris Lattner
66a3e8ba14 Fix <rdar://problem/22344208> QoI: Warning for unused capture list variable should be customized
Where before we produced an invalid and misleading diagnostic, produce a correct one.


Swift SVN r31599
2015-09-01 06:12:39 +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 Willmore
337b52fb1e Use AST function representation info instead of dropping down to SIL.
Swift SVN r31596
2015-09-01 03:27:23 +00:00
Chris Willmore
1c3b391fd3 Don't allow function types that differ in SIL representation to be matched by SameType constraint.
<rdar://problem/22181714> Crash when typing "signal"

Swift SVN r31594
2015-09-01 01:46:59 +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 Willmore
32bcecb2a2 Use Defaultable constraint instead of disjunction for last-resort type.
NFC.

Swift SVN r31393
2015-08-21 21:27:46 +00:00
Chris Willmore
032f7532f7 Don't bind unlabeled type variable to single labeled argument.
<rdar://problem/22348394> Compiler crash on invoking function with labeled defaulted param with non-labeled argument

Swift SVN r31355
2015-08-19 22:57:29 +00:00
Chris Lattner
f6ce68a45a remove ConstraintKind::Conjunction, it is unused and unnecessary - after
all, the whole system is a conjunction!


Swift SVN r31284
2015-08-18 00:47:28 +00:00
Chris Willmore
86f64d3e26 Don't simplify argument tuple conversion constraint $T1 < (T2, ...) to
$T1 < T2 if there are other required params in the tuple.

<rdar://problem/22211854> wrong arg list crashing sourcekit

Swift SVN r31218
2015-08-13 18:28:25 +00:00
Joe Pamer
cd492d96b5 Fix a type checker crash when the object type of a ForceValueExpr is an 'Any'.
This allows us to remove the workaround generic overloads for "print" without sacrificing good diagnostics for its unavailable overloads. (rdar://problem/21499048, rdar://problem/21582758, rdar://problem/22126141)

Swift SVN r31169
2015-08-12 15:59:31 +00:00
Chris Lattner
a899872d91 Reapply r31105, with some fixes to invalid unconstrained generics. These fixes correct
the regressions that r31105 introduced in the validation tests, as well as fixing a number
of other validation tests as well.

Introduce a new UnresolvedType to the type system, and have CSDiags start to use it
as a way to get more type information out of incorrect subexpressions.  UnresolvedType
generally just propagates around the type system like a type variable:
 - it magically conforms to all protocols
 - it CSGens as an unconstrained type variable.
 - it ASTPrints as _, just like a type variable.

The major difference is that UnresolvedType can be used outside the context of a
ConstraintSystem, which is useful for CSGen since it sets up several of them to 
diagnose subexpressions w.r.t. their types.

For now, our use of this is extremely limited: when a closureexpr has no contextual
type available and its parameters are invalid, we wipe them out with UnresolvedType
(instead of the previous nulltype dance) to get ambiguities later on.

We also introduce a new FreeTypeVariableBinding::UnresolvedType approach for
constraint solving (and use this only in one place in CSDiags so far, to resolve
the callee of a CallExpr) which solves a system and rewrites any leftover type 
variables as UnresolvedTypes.  This allows us to get more precise information out,
for example, diagnosing:

 func r22162441(lines: [String]) {
   lines.map { line in line.fooBar() }
 }

with: value of type 'String' has no member 'fooBar'
instead of: type of expression is ambiguous without more context

This improves a number of other diagnostics as well, but is just the infrastructural
stepping stone for greater things.





Swift SVN r31130
2015-08-11 06:06:05 +00:00
Chris Lattner
2204dbcbfd revert r31105, it causes some regressions on validation tests.
Swift SVN r31107
2015-08-10 15:01:22 +00:00
Chris Lattner
de79b60c89 Introduce a new UnresolvedType to the type system, and have CSDiags start to use it
as a way to get more type information out of incorrect subexpressions.  UnresolvedType
generally just propagates around the type system like a type variable:
 - it magically conforms to all protocols
 - it CSGens as an unconstrained type variable.
 - it ASTPrints as _, just like a type variable.

The major difference is that UnresolvedType can be used outside the context of a
ConstraintSystem, which is useful for CSGen since it sets up several of them to 
diagnose subexpressions w.r.t. their types.

For now, our use of this is extremely limited: when a closureexpr has no contextual
type available and its parameters are invalid, we wipe them out with UnresolvedType
(instead of the previous nulltype dance) to get ambiguities later on.

We also introduce a new FreeTypeVariableBinding::UnresolvedType approach for
constraint solving (and use this only in one place in CSDiags so far, to resolve
the callee of a CallExpr) which solves a system and rewrites any leftover type 
variables as UnresolvedTypes.  This allows us to get more precise information out,
for example, diagnosing:

 func r22162441(lines: [String]) {
   lines.map { line in line.fooBar() }
 }

with: value of type 'String' has no member 'fooBar'
instead of: type of expression is ambiguous without more context

This improves a number of other diagnostics as well, but is just the infrastructural
stepping stone for greater things.



Swift SVN r31105
2015-08-10 06:18:27 +00:00
Joe Pamer
828eb68e72 Commit DaveA's API changes to 'print', along with the compiler changes necessary to support them.
There's still work left to do. In terms of next steps, there's still rdar://problem/22126141, which covers removing the 'workaround' overloads for print (that prevent bogus overload resolution failures), as well as providing a decent diagnostic when users invoke print with 'appendNewline'.

Swift SVN r30976
2015-08-04 01:57:11 +00:00
Chris Willmore
3485a97cd4 Diagnose ambiguous initializer resolution.
Fix construction and simplication of constructor member locators, so
that locators involving constructor members can be simplified during
diagnosis.

<rdar://problem/21427130> Swift can't discriminate on arity of function parameters

Swift SVN r30932
2015-08-02 12:12:19 +00:00
Chris Lattner
bb6dfa41cb remove extraneous ;, NFC
Swift SVN r30926
2015-08-02 05:08:02 +00:00
Joe Pamer
d4a9aba927 Expand upon r30921 to allow for remapping against parameter tuples consisting of a single vararg entry. (rdar://problem/18083599)
Swift SVN r30922
2015-08-01 20:18:32 +00:00
Joe Pamer
3fab0eb2db Consider varargs in the first function parameter position when remapping argument constraints to accommodate default values. (rdar://problem/22056861)
Swift SVN r30921
2015-08-01 18:45:31 +00:00
Slava Pestov
20ff9df27f Sema: More robust in the face of missing stdlib protocols
This came up with SourceKit fuzz testing on the stdlib. I don't have a
reduced testcase right now.

Progress on <rdar://problem/19554069>.

Swift SVN r30882
2015-07-31 21:22:51 +00:00
Chris Lattner
7851d348a8 merge the ErrorDoesNotHaveInitOnInstance complexity into the normal
"member not found" diagnostic machinery.


Swift SVN r30842
2015-07-31 04:23:07 +00:00
Chris Lattner
50be7e4ecf reapply r30789, r30795, r30796, r30797, without r30787 which causes a compile time hit:
- Produce more specific diagnostics relating to different kinds of invalid
 - add a testcase, nfc
 - Reimplement FailureDiagnosis::diagnoseGeneralMemberFailure in terms of

Not including r30787 means that we still generate bogus diagnostics like:
[1, 2, 3].doesntExist(0)  // expected-error {{type 'Int2048' does not conform to protocol 'IntegerLiteralConvertible'}}

But it is an existing and separable problem from the issues addressed here.



Swift SVN r30819
2015-07-30 23:31:56 +00:00
Ben Langmuir
c1a2955ef6 Revert r30787, r30789, r30795, r30796, r30797
r30787 causes our tests to time out; the other commits depend on r30787.

Revert "revert part of my previous patch."
Revert "Produce more specific diagnostics relating to different kinds of invalid"
Revert "add a testcase, nfc"
Revert "- Reimplement FailureDiagnosis::diagnoseGeneralMemberFailure in terms of"
Revert "Fix places in the constraint solver where it would give up once a single "

Swift SVN r30805
2015-07-30 17:44:22 +00:00
Chris Lattner
fe04ebfd2f - Reimplement FailureDiagnosis::diagnoseGeneralMemberFailure in terms of
performMemberLookup, eliminating a ton of duplicated logic, but keeping the
  same general behavior.

- Now that r30787 landed, we can have diagnoseGeneralMemberFailure inform
  clients when a member lookup fails due to referencing a candidate decl of
  ErrorType (i.e, it is already invalid somehow).  When this happens, there is
  no reason to diagnose a problem, because the original issue has been diagnosed
  and anything we produce now is just garbage.

The second point cleans up a bunch of bogus diagnostics in the testsuite, which are
*actually* due to upstream error that are already diagnosed.



Swift SVN r30789
2015-07-30 05:28:16 +00:00
Chris Lattner
4fb19ada2b Fix places in the constraint solver where it would give up once a single
constraint failed, leaving a bunch of other solvable constraints laying 
around in the system as inactive.

This is a problem for diagnostics emission, because it turns around and
reaches into the constraint system for some inactive constraint, assuming
that anything left could not be solved.  The constraint system attempted to
solve this by taking the first failure and putting it into the failedConstraint
with the intention of driving diagnostics, but just because it happened to fail
first in constraint-solver-worklist-order doesn't mean it is the most pertinent
one to diagnose.



Swift SVN r30787
2015-07-30 05:08:50 +00:00
Chris Lattner
9df95e8377 Simplify logic in simplifyMemberConstraint, NFC.
Swift SVN r30786
2015-07-30 04:09:08 +00:00
Chris Lattner
17ca02f407 split the meat of simplifyMemberConstraint out into a new
performMemberLookup helper function, this makes it simpler
and enables reuse by CSDiags.


Swift SVN r30775
2015-07-29 19:01:27 +00:00
Chris Lattner
1a0a0315fe wordsmith a diagnostic, NFC otherwise.
Swift SVN r30731
2015-07-28 23:35:25 +00:00
Chris Lattner
ede0c50856 Revamp how value & type member constraint failures are diagnosed, eliminating the
"unavoidable failure" path, along with Failure::DoesNotHaveNonMutatingMember and
just doing some basic disambiguation in CSDiags.

This provides some benefits:
 - Allows us to plug in much more specific diagnostics for the existing "only has 
   mutating members" diagnostic, including producing notes for why the base expr
   isn't mutable (see e.g. test/Sema/immutability.swift diffs).
 - Corrects issues where we'd drop full decl name info for selector references.
 - Wordsmiths diagnostics to not complain about "values of type Foo.Type" instead 
   complaining about "type Foo"
 - Where before we would diagnose all failures with "has no member named", we now
   distinguish between when there is no member, and when you can't use it.  When you
   can't use it, you get a vauge "cannot use it" diagnostic, but...
 - This provides an infrastructure for diagnosing other kinds of problems (e.g. 
   trying to use a private member or a static member from an instance).
 - Improves a number of cases where failed type member constraints would produce uglier
   diagnostics than a different constraint failure would.
 - Resolves a number of rdars, e.g. (and probably others):
   <rdar://problem/20294245> QoI: Error message mentions value rather than key for subscript



Swift SVN r30715
2015-07-28 07:04:22 +00:00
Joe Groff
58ccc8e160 Sema: Check mutating-ness of methods irrespective of reference semantics.
Some types are born to mutating methods, and some types have mutating methods thrust upon them. Protocol extensions put classes into the latter category. A 'mutating' protocol extension method requires a mutable 'self' base even when applied to a class. Fix the synthesized getter for lazy properties so that it's only marked 'mutating' on value types, since otherwise it'd now be impossible to access lazy properties on immutable class references.

Fixes part of rdar://problem/21578832, allowing 'mutating' methods from protocol extensions to apply to mutable class references. Properties with mutating setters are still improperly allowed on immutable class reference bases though.

Swift SVN r30557
2015-07-24 00:10:16 +00:00
Doug Gregor
f00e5bc6ab Allow a variadic parameter anywhere in the parameter list.
Requiring a variadic parameter to come at the end of the parameter
list is an old restriction that makes no sense nowadays, and which we
had all thought we had already lifted. It made variadic parameters
unusable with trailing closures or defaulted arguments, and made our
new print() design unimplementable.

Remove this restriction, replacing it with a less onerous and slightly
less silly restriction that we not have more than one variadic
parameter in a given parameter clause. Fixes rdar://problem/20127197.

Swift SVN r30542
2015-07-23 18:45:29 +00:00
Joe Pamer
a900fd7bc2 Fix a couple of common crashers related to functions with default arguments. (rdar://problem/21799331 and rdar://problem/21643052, plus dupes.)
If a function declaration possessed default parameters, and was invoked with a single argument expression that was modeled as a type variable, the compiler would often crash during type application.  This was due to the fact that during simplification, we would bind the type variable to the full tuple type of the parameter list. Later on, during constraint application, we would then look to whatever expression created the type variable for information on its default arguments - even if no such thing was possible. (E.g., we would examine, say, an IfExpr expecting to find information on its default arguments.) In these cases, we should have instead been binding the argument type variable to the first element of the parameter tuple.

Swift SVN r30486
2015-07-22 01:19:08 +00:00
John McCall
50a667b295 Instead of assuming that the return type of a closure
with no returns *must* be (), add a defaulting constraint
so that it will be inferred as () in the absence of
other possibilities.

The chief benefit here is that it allows better QoI when
the user simply hasn't yet written the return statement.

Doing this does regress a corner case where an attempt
to recover from an uncalled function leads to the
type-checker inferring a result for a closure that
doesn't make any sense at all.

Swift SVN r30476
2015-07-22 00:13:02 +00:00
Devin Coughlin
6ecaca24a3 Sema: Remove leftover availability lookup from treating unavailable symbols as optional. NFC.
This should have been removed in r30355 when I removed the rest of that functionality.

Swift SVN r30422
2015-07-20 22:24:14 +00:00
Chris Lattner
ab487a17b5 Introduce a new TypeCheckExprFlags::AllowUnresolvedTypeVariables option,
which allows solving of a constraint system to succeed without emitting
errors in the face of ambiguous solutions.  This is important for CSDiag
because it is in the business of trying to solve subexpressions of a global
expression - and it wants to know the difference between a subexpression
that is inherently impossible to solve, vs one that is simply ambiguous
because its context has been removed.

Use this in CSDiag's typeCheckChildIndependently() to provide it an
extra flag that enables this behavior.  This is currently unused, so NFC 
with this patch.


Swift SVN r30402
2015-07-20 16:16:54 +00:00
Chris Lattner
a6a172511b Remove duplicated comment.
Swift SVN r30399
2015-07-20 15:55:17 +00:00