Commit Graph

1092 Commits

Author SHA1 Message Date
Mishal Shah
87b7bcfd3e Update master to build with Xcode 8 beta 1, OS X 10.12, iOS 10, tvOS 10, and watchOS 3 SDKs. 2016-06-14 14:53:55 -07:00
Doug Gregor
2b7d0f9379 [Type checker] Extract default argument information from the callee declaration.
Rather than relying on the embedding of default argument information
into tuple types (which is gross), make sure that the various clients
(type checker, type checker diagnostics, constraint application) can
dig out the callee declaration and retrieve that information from
there.
2016-06-09 17:35:12 -07:00
Argyrios Kyrtzidis
dd32ed86fb Follow-up from 7d6f11d217, add space between 'map' and left brace,
per feedback by Dmitri.
2016-06-05 18:13:19 -07:00
Argyrios Kyrtzidis
7d6f11d217 [sema] Follow-up on the raw-representable casting fixits, produce a fixit for optional source types as well.
For optional source types we use the form "expr.map{ T(rawValue: $0) }".
2016-06-05 18:06:14 -07:00
Argyrios Kyrtzidis
f60567e7ba [sema] Follow-up on the raw-representable casting fixits, produce the fixit for optional destination types as well. 2016-06-04 11:22:39 -07:00
Argyrios Kyrtzidis
792ab3c8ed [sema] Add compiler fixit for the case where a raw-representable type is constructed from an argument with the same type.
Like this:

  MyEnumType(MyEnumType.foo)

This is missing 'rawValue:' label, but that won't actually fix this. A better fix is to just remove the unnecessary constructor call:

  MyEnumType(MyEnumType.foo)
-->
  MyEnumType.foo
2016-06-03 07:44:50 -07:00
Argyrios Kyrtzidis
f36cc94f51 [FixCode] Add fix-its for mismatched integer types.
Adds fixits for:
 - Passing an integer with the right type but which is getting wrapped with a
   different integer type unnecessarily. The fixit removes the cast.

 - Passing an integer but expecting different integer type. The fixit adds
   a wrapping cast.
2016-05-31 22:29:28 -07:00
Robert Widmann
054f2ffa1a Resolve SR-1594 2016-05-31 16:49:11 -07:00
Slava Pestov
4558b5018c Sema: New fix-its for RawRepresentable conversions
If the expression type is RawRepresentable with an associated
RawValue type of T, and the contextual type is T, suggest adding
a '.rawValue' accessor call.

Also, suggest inserting the fixit in a few more cases, such as
dictionary keys.

This improves upon a previous patch which added a fix-it for the
other direction:

<55bf215feb>

Fixes <rdar://problem/26470490>.
2016-05-27 00:26:21 -07:00
Argyrios Kyrtzidis
4b5e617869 [sema] Add some comments as follow-up for 55bf215feb. NFC. 2016-05-25 14:20:35 -07:00
Argyrios Kyrtzidis
55bf215feb [sema] When the error is "cannot convert value of type <integer> to expected argument type <RawRepresentable>" add a fixit.
The fixit constructs the raw-representable type from the value. This helps with SDK changes.
2016-05-25 07:23:57 -07:00
John McCall
f424b27f7d Use a specialized diagnostic to report that the result of ? : is not mutable.
I *think* that conditional l-values are supportable in all cases, but
it would take quite a bit of work, and we haven't done that work.
2016-05-13 13:39:49 -07:00
John McCall
a1c1693529 Change the names of the object-literal initializers to be
semantically unambiguous.

We didn't actually intend to change how programmers normally
constructed these types, but the change to the object literal
syntax accidentally caused these initializers to have very
natural-seeming signatures.  These initializers also created
possible ambiguities with the actual initializers.  Renaming
them to refer to their function as literal initializers is the
right thing to do.

Unfortunately, this provided to be somewhat annoying, as the
code was written to assume that the argument tuple following
e.g. #colorLiteral could be directly passed to the initializer.
We solve this by hacking on both ends of the constraint system:
during generation we form a conversion constraint to the
original, idealized parameter type, and during application we
rewrite the argument tuple type to use the actual labels.
This nicely limits the additional complexity to just the
parts dealing with object literals.

Note that we can't just implicitly rewrite the tuple expression
because that would break invariants tying the labels to physical
source ranges.  We also don't want to just change the literal
syntax again and break compatibility with existing uses.

rdar://26148507
2016-05-13 10:33:37 -07:00
John McCall
e75dae491e Don't diagnose failures to call symmetrically-typed binary operators
as a failure to convert the individual operand, since the operator
is likely conceptually generic in some way and the choice of any
specific overload is probably arbitrary.

Since we now fall back to a better-informed diagnostics point, take
advantage of this to generate a specialized diagnostic when trying to
compare values of function type with ===.

Fixes rdar://25666129.

This reverts commit 073f427942,
i.e. it reapplies 35ba809fd0 with a
test fix to expect an extra note in one place.
2016-05-11 16:09:28 -07:00
Ted Kremenek
073f427942 Revert "Don't diagnose failures to call symmetrically-typed binary operators"
This reverts commit 35ba809fd0.
2016-05-11 15:53:24 -07:00
John McCall
35ba809fd0 Don't diagnose failures to call symmetrically-typed binary operators
as a failure to convert the individual operand, since the operator
is likely conceptually generic in some way and the choice of any
specific overload is probably arbitrary.

Since we now fall back to a better-informed diagnostics point, take
advantage of this to generate a specialized diagnostic when trying to
compare values of function type with ===.

Fixes rdar://25666129.
2016-05-11 15:10:25 -07:00
Ted Kremenek
942e524285 Revert "SE-0036: Requiring Leading Dot Prefixes for Enum Instance Member Implementations" (#2477) 2016-05-11 11:02:37 -07:00
Alex Hoppen
0e8c69c56f [SE-0036]: Requiring Leading Dot Prefixes for Enum Instance Member Implementations 2016-05-07 22:39:26 +02:00
Jordan Rose
797260939e Handle argument labels in @available(renamed:"...")
Fixes SR-1008 / rdar://problem/25276961
2016-04-28 20:21:30 -07:00
Jordan Rose
ec59bf9f18 Move helper function 'diagnoseArgumentLabelError' to MiscDiagnostics.
Groundwork for SR-1008. No functionality change.
2016-04-28 20:21:30 -07:00
Ted Kremenek
b8bbed8c13 [WIP] Implement SE-0039 (Modernizing Playground Literals) (#2215)
* Implement the majority of parsing support for SE-0039.

* Parse old object literals names using new syntax and provide FixIt.

For example, parse "#Image(imageLiteral:...)" and provide a FixIt to
change it to "#imageLiteral(resourceName:...)".  Now we see something like:

test.swift:4:9: error: '#Image' has been renamed to '#imageLiteral
var y = #Image(imageLiteral: "image.jpg")
        ^~~~~~ ~~~~~~~~~~~~
        #imageLiteral resourceName

Handling the old syntax, and providing a FixIt for that, will be handled in a separate
commit.

Needs tests.  Will be provided in later commit once full parsing support is done.

* Add back pieces of syntax map for object literals.

* Add parsing support for old object literal syntax.

... and provide fixits to new syntax.

Full tests to come in later commit.

* Improve parsing of invalid object literals with old syntax.

* Do not include bracket in code completion results.

* Remove defunct code in SyntaxModel.

* Add tests for migration fixits.

* Add literals to code completion overload tests.

@akyrtzi told me this should be fine.

* Clean up response tests not to include full paths.

* Further adjust offsets.

* Mark initializer for _ColorLiteralConvertible in UIKit as @nonobjc.

* Put attribute in the correct place.
2016-04-25 07:19:26 -07:00
Jordan Rose
405bfdc33b [Sema] Add a fix-it for non-optional bindings initialized with nil.
<stdin>:1:16: error: nil cannot initialize specified type 'Int'
var foo: Int = nil
               ^
<stdin>:1:10: note: add '?' to form the optional type 'Int?'
var foo: Int = nil
         ^
            ?
2016-04-21 13:36:54 -07:00
Jordan Rose
16f857c78c [Sema] Use a TypeLoc for conversions with contextual types.
With a TypeLoc, we have a chance to offer diagnostics or even fix-its
to the contextual type, even though it's not represented by an
expression in the constraint system. This commit mostly just passes it
through, without attempting to use it anywhere or even pass a real
TypeLoc (with a valid TypeRepr).

(It does drop the contextual type parameter from
typeCheckExpressionShallow, since there were zero callers using it.)

No functionality change...yet.
2016-04-21 13:36:53 -07:00
Chris Lattner
8e12008d2b Mark tuple splat and ++/-- as errors instead of warnings. This
wraps up SE-0004 and SE-0029.

I consider the diagnostic changes in Constraints/lvalues.swift to be
indicative of a QoI regression, but I'll deal with that separately.
2016-04-16 23:44:22 -07:00
Chris Lattner
228bee7689 Rearrange how CalleeCandidateInfo processes candidates in its list, to
make sure that properties and subscripts have a self type in their tracked
type.  This makes SubscriptExpr processing more logical (given that it applies
both self and an index list), by putting hacks in more principled places.

It would be great to someday eliminate SubscriptExpr entirely, but this isn't
going to happen in the short term.  NFC.
2016-04-13 22:55:55 -07:00
Jordan Rose
bc83940301 Make pointer nullability explicit using Optional.
Implements SE-0055: https://github.com/apple/swift-evolution/blob/master/proposals/0055-optional-unsafe-pointers.md

- Add NULL as an extra inhabitant of Builtin.RawPointer (currently
  hardcoded to 0 rather than being target-dependent).
- Import non-object pointers as Optional/IUO when nullable/null_unspecified
  (like everything else).
- Change the type checker's *-to-pointer conversions to handle a layer of
  optional.
- Use 'AutoreleasingUnsafeMutablePointer<NSError?>?' as the type of error
  parameters exported to Objective-C.
- Drop NilLiteralConvertible conformance for all pointer types.
- Update the standard library and then all the tests.

I've decided to leave this commit only updating existing tests; any new
tests will come in the following commits. (That may mean some additional
implementation work to follow.)

The other major piece that's missing here is migration. I'm hoping we get
a lot of that with Swift 1.1's work for optional object references, but
I still need to investigate.
2016-04-11 20:06:38 -07:00
Josef Willsher
de18967992 [Sema] Improved error message for static functions on existential metatypes (#2127)
Type level lookups can fail because the lookup is on an existential
metatype, like `MyProtocol.staticMethod(_:)` is invalid; however the
error message is unclear: “static member 'staticMethod(_:)' cannot be
used on instance of type ‘MyProtocol.Protocol’”.

This fix checks the base of member lookups that failed with the reason
UR_TypeMemberOnInstance for being existential metatypes. It produces
the clearer message “static member ‘staticMethod(_:)’ cannot be used on
protocol metatype ‘MyProtocol.Protocol’”. This change makes it clear
that the use of a static member on the *existential* metatype is the
problem.
2016-04-10 19:03:20 -07:00
practicalswift
abfecfde17 [gardening] if ([space]…[space]) → if (…), for(…) → for (…), while(…) → while (…), [[space]x, y[space]] → [x, y] 2016-04-04 16:22:11 +02:00
Chris Lattner
514ec31114 Progress towards SR-1069:
- Fix ExprTypeSaverAndEraser to save & restore the invalid bit on closure parameter decls.
 - Teach CalleeCandidateInfo::evaluateCloseness to not try to find generic subs on types that
   contain a unresolved type within them.

With these changes, the compiler doesn't segfault on the testcase when assertions are
enabled.  It still doesn't produce a great diagnostic though.
2016-03-29 22:33:07 -07:00
Chris Lattner
59425c086d fix <rdar://problem/21523291> compiler error message for mutating immutable field is incorrect 2016-03-22 16:57:09 -07:00
Chris Lattner
a12674a571 When reporting a type error relating to the result type of an overload
set where all members of the set produce the same type, produce a more
specific error.

Before:

t.swift:4:17: error: no '&&' candidates produce the expected contextual result type 'Int'
  return a == b && 1 == 2
                ^
t.swift:4:17: note: produces result of type 'Bool'
  return a == b && 1 == 2
                ^

after:

t.swift:4:17: error: '&&' produces 'Bool', not the expected contextual result type 'Int'
  return a == b && 1 == 2
                ^

This improves the situation reported in https://twitter.com/_jlfischer/status/712337382175952896
2016-03-22 15:45:52 -07:00
Chris Lattner
e1ad6d80ee fix 28270-swift-constraints-constraintsystem-diagnosefailureforexpr.swift 2016-03-14 11:56:32 -07:00
Max Moiseev
1fae0d1325 Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-03-08 12:48:48 -08:00
Chris Lattner
aacdf62e8b fix some whitespace issues noticed by Slava. 2016-03-07 23:11:45 -08:00
Chris Lattner
14b5b0a73f Resolve the QoI fixme's from the generic typealiases testcase, by specifying the
correct location for generic parameters that cannot be inferred.  The cases that
I thought were incorrectly rejected on first glance were actually correct.
2016-03-07 23:04:38 -08:00
Max Moiseev
7fe6916bf6 Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-03-07 12:10:47 -08:00
Greg Titus
f6c59815ca Merge pull request #1504 from gregomni/sr-839
[SR-839][Sema] Better fixits for optional expressions
2016-03-04 18:16:36 -08:00
Max Moiseev
cf4bafe9e3 Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-03-03 13:22:03 -08:00
Janek Spaderna
15f128bf4f [Sema] Don't crash on mutating getters on constants
With this change the base expression of the subscript (beeing already
revalidated earlier in the function) is passed to diagnoseUnviableLookupResults
to emit a fitting diagnostic.
2016-03-03 00:09:32 +01:00
gregomni
098f8e0ebf [SR-839][Sema] Better fixits for optional expressions
In member ref expressions, if the base is optional, and the expected
expression result is either optional or unknown, suggest a fixit that
makes it into an optional chain expr rather than force unwrapping.

Since in many cases the actual fixit is emitted during diagnosis, and
thus, while type checking sub exprs with no contextual type specified
(so nothing to check for preferring optionality), we also need an
additional flag to pass down from FailureDiagnosis for whether we
prefer to fix as force unwrapping or optional chaining.

I attempted to do this same job via providing a convert type but
setting the ConvertTypeIsOnlyAHint flag on the type checker, but
unfortunately there are a lot of other moving parts that look at that
type, even if it is only supposed to be a hint, so an additional flag
to the CS ended up being cleaner.
2016-03-01 22:57:24 -08:00
Max Moiseev
a49dab6bf8 Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-29 12:08:52 -08:00
Chris Lattner
19b6ab8408 fix <rdar://problem/24251022> Swift 2: Bad Diagnostic Message When Adding Different Integer Types
Previously we would produce:

t.swift:3:3: error: binary operator '+=' cannot be applied to operands of type 'Int' and '_'
a += a + b
~ ^  ~~~~~

with a candidate set to follow.  Now we properly match up the inout/lvalue type and produce
the following more specific diagnostic:

t.swift:3:10: error: cannot convert value of type 'UInt32' to expected argument type 'Int'
a += a + b
         ^

pointing the the "b".
2016-02-28 20:52:33 -08:00
Dmitri Gribenko
dd75aed67a Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-17 14:40:05 -08:00
gregomni
f8dbb20a19 [Sema] Extend callee diagnosis to multiple generics
Straightforward extension of the previous work here to handle callees
with multiple generic parameters. Same type requirements are already
handled by the ArchetypeBuilder, and protocol conformance is handled
explicitly. This is still bailing on nested archetypes.

Pre-existing tests updated that now give better diagnoses.
2016-02-15 15:52:24 -08:00
Max Moiseev
3a3984877a Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-15 15:43:34 -08:00
gregomni
10370a5c0f Extend callee diagnoses to non-conforming complex args including generics.
Previously, type checking arguments worked fine if the entire arg was
UnresolvedType, but if the type just contained UnresolvedType, the
constraint system always failed via explicitly constraining to
unresolved.

Now in TypeCheckConstraints, if the solution allows for free variables
that are UnresolvedType, then also convert any incoming UnresolvedTypes
into variables. At worst, in the solution these just get converted back
into the same Unresolved that they started with.

This change allows for incorrect tuple/function type possibilities to
make it back out to CSDiag, where they can be more precisely diagnosed
with callee info. The rest of the changes are to correctly figure
out the failure info when evaluating more types of Types.

New diagnosis for a partial part of an arg type not confroming. Tests
added for that. Expected errors changed in several places where we
now get real types in the diagnosis instead of '(_)' unresolved.
2016-02-14 11:32:14 -08:00
Chris Lattner
b2fabdadcc move diagnoseArgumentLabelError to CSDiags.cpp now that it is the only client. 2016-02-12 17:33:22 -08:00
Chris Lattner
cf2e7f6f45 Fix SR-718: Type mismatch reported as extraneous parameter
The issue here is that the constraint solver was deciding on
FixKind::RelabelCallTuple as the fix for the problem and emitting the
diagnostic, even though there were two different fixes possible.

CSDiags has the infrastructure to support doing doing the right thing
here, but is only being used for ApplyExprs, not SubscriptExprs.

The solution is to fix both problems: remove FixKind::RelabelCallTuple,
to let CSDiags handle the problem, and enhance CSDiags to treat
SubscriptExpr more commonly with ApplyExpr.  This improves several cases
where the solver was picking one solution randomly and suggesting that
as a fix, instead of listing that there are multiple different solutions.
2016-02-12 17:19:54 -08:00
Robin Kunde
90b6f0e2a8 added improved diagnostic notes in case of missing binary operator overload for enums with associated values 2016-02-10 09:03:10 -05:00
Chris Lattner
836b88e320 refactor some code into a helper method, NFC. 2016-02-08 10:06:03 -08:00