Commit Graph

5910 Commits

Author SHA1 Message Date
Denis Vnukov
4f92a08987 Adding a location of the var/let/inout to ParamDecl 2016-01-27 13:43:42 -08:00
Denis Vnukov
7b3b7a35d0 Don't skip creating CoerceExpr in case forced_downcast_noop warning 2016-01-27 13:43:41 -08:00
Denis Vnukov
db6582c72b Fixed several AST nodes wrongly marked with implicit/explicit flag 2016-01-27 13:43:39 -08:00
practicalswift
ad2884a91d [gardening] Fix recently introduced typo: "arguement" → "argument" 2016-01-27 22:23:13 +01:00
Chris Lattner
0dcd84ff2f Merge pull request #1107 from ahoppen/master
[Sema] Fix SR-590 Passing two parameters to a function that takes one…
2016-01-27 10:56:39 -08:00
Chris Lattner
16a0d7bf63 Merge pull request #1089 from gregomni/generic-func-args
[Sema] Further improvement of diagnoses on args to generic functions
2016-01-27 10:55:07 -08:00
Doug Gregor
dccf3155f1 SE-0022: Implement parsing, AST, and semantic analysis for #selector. 2016-01-26 21:12:04 -08:00
gregomni
e811a64af3 Further improvement of diagnoses on args to generic functions
If the mismatched argument is on an archetype param, check to see
whether the argument conforms to all of the protocols on the archetype,
using a specific does-not-conform diagnosis if one or more protocols
fail.

Also added another closeness class
`CC_GenericNonsubstitutableMismatch`, which happens when more than one
argument is a mismatch, but all the failing arguments are of the same
type and mismatch only because of substitutability. This closeness is
farther away than normal `CC_ArgumentMismatch` so that if we note
expected matches, we’ll prefer non-generic matches. But if this is the
result, we can still produce the specific conforms-to-protocol
diagnosis (since, in a sense, it’s only one type of argument that is
wrong even though it is multiple arguments).
2016-01-26 20:07:20 -08:00
Alex Hoppen
b54976baba [Sema] Fix SR-590 Passing two parameters to a function that takes one argument of type Any crashes the compiler 2016-01-26 22:47:14 +01:00
Chris Lattner
b5694e941e fix 28241-swift-valuedecl-isaccessiblefrom.swift 2016-01-25 22:06:14 -08:00
Chris Lattner
2dfab70665 fix <rdar://24314506> QoI: Fix-it for dictionary initializer on required class var suggests [] instead of [:]
a simple apparent typo or thinko
2016-01-25 21:03:48 -08:00
Doug Gregor
8336419844 Include completion source location information compound DeclNames.
When one spells a compound declaration name in the source (e.g.,
insertSubview(_:aboveSubview:), keep track of the locations of the
base name, parentheses, and argument labels.
2016-01-25 14:13:13 -08:00
practicalswift
c8ad360f8d [gardening] Fix recently introduced typo 2016-01-25 22:26:15 +01:00
Slava Pestov
d791213bba Merge pull request #1083 from JaSpa/cleanup-resolveTypeInContext
[Sema] Cleanup resolveTypeInContext
2016-01-25 12:29:09 -08:00
Janek Spaderna
24b5c4cd1b Move logic into one place by merging the first loop into the second
Now all the logic to resolve a type by iterating through the decl context hierarchy is moved into one place.
2016-01-25 20:43:23 +01:00
practicalswift
71e00fefa1 [gardening] Fix typos: "word word" (two spaces) → "word word" (one space) 2016-01-24 21:27:16 +01:00
Janek Spaderna
1f0643f404 Correctly resolve associated types in nested protocols
The problem was that an associated type was always resolved with the nearest protocol `Self` as a reference, but in the case of nested protocols the associated type might be from the enclosing protocol leading to a crash.

We now enumerate in a bottom-up way through the contexts until we have found the correct protocol which provides us with the `Self` reference to resolve the associated type.
2016-01-24 14:42:18 +01:00
practicalswift
f19464079a [gardening] Fix recently introduced typo 2016-01-24 08:48:42 +01:00
Chris Lattner
e9d1857ca3 Fix rdar://21783216 QoI: Cannot convert {TYPE} to {SAME TYPE}
which was reported here: https://twitter.com/jadengeller/status/619989059046240256

The underlying problem here is that the user was defining an associated
type named "Type", and then trying to refer to it with stuff.Type.  The
problem is that stuff.Type is a reserved way to refer to the metatype.

Solve this sort of confusion by banning type members named Type (and
Protocol, while we're here) since forming a reference to them won't
work.  This produces a note that indicates that a backtick'd version
of the identifier will work, since "stuff.`Type`" will correctly form
the reference to it.

This only bans type members named Type or Protocol, but we could consider
banning all ValueDecls from being named Type or Protocol.  Module
qualification isn't widely used though, and metatypes of modules don't
really make sense at the moment.
2016-01-23 14:45:06 -08:00
practicalswift
8efa5f587e [gardening] Remove "-*- C++ -*-" tag from .cpp files
Emacs assumes .h files are C files by default which is why the
tag "-*- C++ -*-" is needed.

.cpp files do not have this problem.
2016-01-23 12:09:32 +01:00
practicalswift
a3f857ca7b [gardening] Add "-*- C++ -*-" to header files currently missing it 2016-01-23 11:53:05 +01:00
Chris Lattner
995506a5e2 Improve the generic "expression...is ambiguous without more context" error in a few ways:
- Improve the specific cases of nil and empty collection literals.
- Improve cases of contextual member lookup where the result type of the looked up member disagrees with context.
- Add some fixme's to the testsuite for cases of this diagnostic that should be diagnosed in other ways.
2016-01-22 22:58:26 -08:00
Chris Lattner
2d9114665c Implement <rdar://22207630> QoI: UncurriedCandidate should handle ClosureExprs
This standardizes processing of callees in invalid applyexprs, eliminating
bogus diagnostics like:
t.swift:6:2: error: cannot invoke closure of type '() -> _' with an argument list of type '()'

we now properly diagnose the example in closure/closures.swift as ambiguous,
but don't do a particularly good job of saying why.  That is to follow.
2016-01-22 20:33:23 -08:00
Chris Lattner
cd731df0cf Eliminate the argsHaveTrailingClosure argument to evaluateCloseness
now that we can get it off of "this". NFC.
2016-01-22 20:02:06 -08:00
Chris Lattner
59e0b2d347 Fix rdar://21311590 QoI: Inconsistent diagnostics when no constructor is available
In the case of an invalid override of an init, mark the override invalid, not the
init.  This way, code that uses the init can be parsed and analyzed correctly and
bogus downstream errors are reduced.

Before:

t.swift:2:12: error: initializer does not override a designated initializer from its superclass
  override init() {}
  ~~~~~~~~ ^
t.swift:5:1: error: cannot invoke initializer for type 'C' with no arguments
C()
^
t.swift:6:1: error: 'B' cannot be constructed because it has no accessible initializers
B()
^

After:

t.swift:2:12: error: initializer does not override a designated initializer from its superclass
  override init() {}
  ~~~~~~~~ ^
2016-01-22 17:42:42 -08:00
Chris Lattner
554b7d0525 Fix SR-596 - Compiler crashes when accesing a non-existent property of a closure parameter
This crash was a bug in computeTupleShuffle handling conversions to
a parameter list with a varargs argument in the middle of the list.
In this case, it is coming from the parameter list for Swift.print.
2016-01-22 17:22:14 -08:00
Joe Pamer
50749dfcd0 Re-enable contractions for parameter binding constraints between identical type variables.
In these cases, we should just go ahead and remove the redundant constraints:
- They don't help us derive a solution for the system
- Not doing so might leave "dangling" constraints that will make the system unsolvable
2016-01-22 17:06:22 -08:00
Chris Lattner
c72b337af1 Fix SR-599 - Function with unresolved generic diagnosed as property
There are two problems here, first we were diagnosing type member
constraints with the "function 'foo' was used as a property" error,
which doesn't make sense.

Second, we were diagnosing member constraints as lookup failures when
the constraint was actually referring to an archetype in its anchor
expression that wasn't resolved.  Address this by simply ignoring the
constraint and letting ambiguity resolution handle it.

Before:
t.swift:5:9: error: function 'foo' was used as a property; add () to call it

After:
t.swift:5:9: error: generic parameter 'T' could not be inferred
let a = foo()
t.swift:4:6: note: in call to function 'foo'
func foo<T: IntegerType>() -> T.Type { return T.self }

Thanks to Jordan for noticing this!
2016-01-22 16:10:04 -08:00
Joe Pamer
32121ecdc6 Pending further work, do not contract related parameter binding constraints that refer to the same type variable. (E.g., "$0 == $0") 2016-01-22 15:29:56 -08:00
practicalswift
45049f2763 [gardening] Fix recently introduced typos 2016-01-22 22:37:54 +01:00
Chris Lattner
7bb053eb2f Enhance performMemberLookup/lookupMemberType to pass down
"includeInaccessibleMembers" to the lookups it does on all paths
for consistency.

These aren't being exercised yet, so NFC.
2016-01-22 13:19:05 -08:00
Chris Lattner
e15d08e38f Merge pull request #1042 from gregomni/sr-69
[SR-69][Sema] Improved quality of diagnoses messages
2016-01-22 13:18:56 -08:00
Joe Pamer
a59e78749d - When simplifying constraint systems generated for deeply nested binary expressions with homogeneous argument types, directly bind the parameter type variable to the argument type. This generally improves type check performance of such expressions.
- Fix the test invocation of a fixed compiler crasher - it now compiles and runs cleanly.
2016-01-22 12:34:34 -08:00
Joe Pamer
bbf0c1e8b9 Introduce limited support for subtype constraint contractions, with special support for solving over implicit closure parameters with inferred inout types. 2016-01-22 12:34:34 -08:00
Joe Pamer
0b6b301f1c Reinstate code that was dropped during a rebase operation. 2016-01-22 12:34:34 -08:00
Joe Pamer
de3d8a5823 More effectively simplify constraint graphs for nested binary expressions with homogeneous argument types. For example, this allows us to typecheck expressions of the form "a + b + c + d", where each variable is of an array type, without getting a "too complex" error.
Note that the typecheck perf for these kinds of expressions still isn't fantastic, but at least they're now computationally feasible. I have further improvements planned for this area which should bring performance in line with expectations.
2016-01-22 12:34:34 -08:00
Joe Pamer
995913e1a5 Begin favoring the expected types of closures with single-expression bodies. 2016-01-22 12:34:34 -08:00
Joe Pamer
5f9d3f83c7 When deciding whether to favor an overload binding constraint for a binary operator, only propagate favored types downward if there's a good chance that the operator has symmetric operands (as for certain arithmetic operators, for example). 2016-01-22 12:34:33 -08:00
Joe Pamer
3aeed2736b Introduce more refinements to how certain linked expr kinds are analyzed before performing edge contraction. 2016-01-22 12:34:33 -08:00
Joe Pamer
e3752c0720 In the LinkedExprAnalyzer, merge equivalence classes directly, rather
than create redundant constraints that will later be removed.
2016-01-22 12:34:33 -08:00
Joe Pamer
0e149db993 Being updating LinkedExprAnalyzer to work with the edge contractor. 2016-01-22 12:34:33 -08:00
Joe Pamer
762fc2a0ab - Do not update the work list whilst contracting edges.
- Temporarily disable contraction of conversion constraints.
2016-01-22 12:34:33 -08:00
Joe Pamer
33bbe2c787 Account for generated constraints when removing edges from the constraint graph. 2016-01-22 12:34:33 -08:00
Joe Pamer
fb03b7974a Pave the way for contracting edges between closure parameter bindings. 2016-01-22 12:34:33 -08:00
Joe Pamer
c8ac294ea4 - Consider parameter bindings
- Slightly improve logging for contractions
2016-01-22 12:34:32 -08:00
Joe Pamer
5afd794860 Slightly improve logging for overload resolution. 2016-01-22 12:34:32 -08:00
Joe Pamer
37032b2a58 Take first steps towards simplifying the constraint graph by performing edge contraction. 2016-01-22 12:34:32 -08:00
Chris Lattner
c64b78c5bc When doing name lookups for diagnostics, use NameLookupFlags::KnownPrivate
unconditionally.  Thanks to Jordan for suggesting this.
2016-01-22 12:05:59 -08:00
Chris Lattner
6723acccf9 Use TypeExpr::getInstanceType to simplify some code, NFC. 2016-01-22 12:05:59 -08:00
gregomni
05ebb021ba Add a slightly less close than CC_OneArgumentMismatch closeness.
Producing single argument mismatches involving generics causes some
gross looking error messages if the generic mismatches get put into the
same closeness bucket as non-generic mismatches.

E.g. `var v71 = true + 1.0` used to produce `error: cannot convert
value of type 'Bool' to expected argument type 'Double’`, but would now
end up with `binary operator '+' cannot be applied to operands of type
'Bool' and 'Double’` `overloads for '+' exist with these partially
matching parameter lists: (Double, Double), (T, T.Stride), (T.Stride,
T)`.

Resolve this by adding CC_OneGenericArgumentNearMismatch and
CC_OneGenericArgumentMismatch, that are similar but ever so slightly
not as close as a mismatch involving non-generic functions. This gets
back the original error message in cases like the above, because there
is only one declaration of `+` which partially matches and is
non-generic, and the generic partial matches are now farther away.

But now single arg mismatches and nearness work for single-archetype
generic functions, as in the additions to the SR-69 test at the end of
deduction.swift.
2016-01-22 10:24:03 -08:00