Commit Graph

4105 Commits

Author SHA1 Message Date
Doug Gregor
beb43749f1 Suggest '&' when it is needed to pass an lvalue by reference.
Fixes <rdar://problem/11592572>.

Swift SVN r16944
2014-04-27 21:42:06 +00:00
Doug Gregor
eaf2bf632f Speculatively fix optionals by unwrapping them with '!'.
Example:

test/Constraints/fixes.swift:54:9: error: value of optional type 'B?'
    not unwrapped; did you mean to use '!' or '?'?
  b = a as B
        ^
            !

Swift SVN r16938
2014-04-27 20:41:02 +00:00
Doug Gregor
321911a059 Add infrastructure for applying fixes during constraint solving.
Introduce some infrastructure that allows us to speculatively apply
localized fixes to expressions during constraint solving to fix minor
typos and omissions. At present, we're able to introduce the fixes
during constraint simplification, prefer systems with fewer fixes when
there are multiple fixes, and diagnose the fixes with Fix-Its.

Actually rewriting the AST to reflect what the Fix-Its are doing is
still not handled.

As a start, introduce a fix that adds '()' if it appears to have been
forgotton, producing a diagnostic like this if it works out:

t.swift:8:3: error: function produces expected type 'B'; did you mean
to call it with '()'?
f(g)
  ^
   ()

Note that we did regress in one test case
(test/NameBinding/multi-file.swift), because that diagnostic was
getting lucky with the previous formulation.

Swift SVN r16937
2014-04-27 19:04:04 +00:00
Chris Lattner
371a9316f4 - Introduce a new 'nonmutating' context sensitive keyword, and use it instead of @!mutating.
- Change the parser to unconditionally reject @mutating and @!mutating with a fixit and 
  specific diagnostic to rewrite them into the [non]mutating keyword.
- Update tests.

This resolves <rdar://problem/16735619> introduce nonmutating CS keyword and remove the attribute form of mutating all together



Swift SVN r16892
2014-04-26 21:00:06 +00:00
Chris Lattner
740e102366 resolve <rdar://problem/16563853> 'break' should be able to break out of switch statements
now that we've had two submissions rejecting break in a switch statement.


Swift SVN r16891
2014-04-26 20:12:05 +00:00
Doug Gregor
11fa610a51 Variadic functions cannot be @objc.
Our models for variadics are too different. Fixes <rdar://problem/16732169> .

Swift SVN r16856
2014-04-25 23:51:14 +00:00
Doug Gregor
5ac2e3df51 Make protocol conformance require equivalent keyword arguments.
Provide the same declaration-fixing QoI we have for overrides.


Swift SVN r16850
2014-04-25 23:09:51 +00:00
Doug Gregor
5a61f9b0d7 Ban optional initializers in protocols. <rdar://problem/16669554>
Swift SVN r16824
2014-04-25 16:53:05 +00:00
Doug Gregor
bf4967958a When overriding a method or initializer, require the full names to match.
Do some QoI heroics here so that we get good diagnostics and Fix-Its
when we attempt to override but fail to do so because one picked
different argument names.

Swift SVN r16784
2014-04-25 00:32:42 +00:00
Doug Gregor
eb0a082614 Restore the name into the "previous declaration was here" note.
The previous declaration may have a different full name from the
declaration, and may show up in a module, in which case it's useful to
have the name.



Swift SVN r16700
2014-04-23 13:30:04 +00:00
Doug Gregor
9ccaf63998 Implement sane redeclaration checking.
Perform redeclaration checking of global and type-member declarations
at the time of declaration, using a notion of the signature of a
declaration to determine when one declaration is a redeclaration of
another. See ValueDecl::getOverloadSignature() and 
conflicting(OverloadSignature, OverloadSignature) for the specific
rules we implement. In a nutshell:

  - For functions, the signature includes:
    + The full name (which includes argument names)
    + The interface type
    + Whether the function is a class/static or instance method
    + For an operator, whether it is prefix or postfix
  - For a subscript, the signature is the interface type
  - For everything else, the signature is just the name

This tightens the rules in a number of ways, which is reflected in the
test case churn:

  - We now properly perform redeclaration checking for generics
  - We now propertly handle API argument names for functions
  - We now ban overloading between two variables of the same name but
    different type 
  - We now ban overloading between a variable/property and a function
  - We now ban overloading for initializers

The two test cases of actual interest are:

  test/decl/overload.swift: A bunch of new test cases for our checking

  test/Constraints/members.swift: I commented out a useful test for
  now, because it relies on overloading between a property and a
  function. We can reconsistute this test with a couple of modules.

This commit fixes at least a half dozen radars under the umbrella
<rdar://problem/11212777>. I still need to check them individually to
close them out.



Swift SVN r16691
2014-04-23 07:03:38 +00:00
Chris Lattner
5c19f8f84b implement <rdar://problem/16692437> shadowing loop labels should be an error
Swift SVN r16672
2014-04-22 22:52:18 +00:00
Chris Lattner
411e5baf02 revert r16670, which included more than it should have.
Swift SVN r16671
2014-04-22 22:51:26 +00:00
Chris Lattner
4fc1154ca7 implement <rdar://problem/16692437> shadowing loop labels should be an error
Swift SVN r16670
2014-04-22 22:50:46 +00:00
Jordan Rose
4a36db7835 [serialization] Print the path to a too-new, too-old, or malformed module file.
<rdar://problem/16680615>

Swift SVN r16637
2014-04-22 01:51:19 +00:00
Chris Lattner
0a5b27baf4 Implement labeled break/continue support, implementing rdar://11562938.
Right now you can 'break' out of a labeled switch statement, but unlabeled 
break retains its previous semantics of breaking out of the nearest loop.


Swift SVN r16616
2014-04-21 14:38:16 +00:00
Chris Lattner
7e93a509a9 enhance the AST representation of break and continue statements to specify the
LabeledStmt that they target: have sema fill this in, and make silgen respect it.

NFC, because this was specifically written to behave the same as before (e.g. no
break out of switches).


Swift SVN r16610
2014-04-21 05:53:44 +00:00
Chris Lattner
33d132b30d finish off the rest of the @NSCopying attribute, checking conformance to the
NSCopying protocol and diagnosing it nicely, instead of just barfing in the
synthesized function.

The implementation of getNSCopyingProtocol is not right here (it is doing an
unqualified lookup for the protocol).  I could not find another way to get
the NSCopying protocol.  Suggestions appreciated.


Swift SVN r16560
2014-04-19 01:05:19 +00:00
Chris Lattner
c316556974 Fix <rdar://problem/16659058> Read-write properties can be made read-only in a property override
If you want to override just a getter (or setter) then you need to implement both, and have the
other one chain to super.


Swift SVN r16541
2014-04-18 19:50:43 +00:00
Doug Gregor
8bc2ea4ea1 Use designated/convenience initializer terminology throughout. NFC
Introduce CtorInitializerKind to describe the kind of an enum, rather
than a bool, to make way for more initializer kinds in the future.

Swift SVN r16525
2014-04-18 15:10:13 +00:00
Nadav Rotem
2dd564b102 Change the diagnostics message to: "immutable value of type ‘X’ only has mutating members named ‘Y'"
Swift SVN r16458
2014-04-17 16:53:08 +00:00
Nadav Rotem
960a6f2892 Improve the diagnostics of access to non-mutating members.
Swift SVN r16446
2014-04-17 06:34:15 +00:00
Chris Lattner
adff5375fe Initial support for the @NSCopying attribute on properties. This is enough to
wire it up, do basic semantic analysis and code gen a simple case of it.  There is
more type checking work to come, so it isn't complete yet.

This is the first step to:
<rdar://problem/15864836> Need a @NSCopying attribute for Cocoa types that aren't manually bridged



Swift SVN r16345
2014-04-15 00:31:59 +00:00
Doug Gregor
53b84c121e Switch ValueDecl::getObjCSelector() and friends over to ObjCSelector.
Formatting names into strings repeatedly, and using those for semantic
analysis, is generally considered poor form. Additionally, use the
camelCase utilities to perform the string manipulation we need, and
cache results on the ObjCAttr so we don't repeatedly do string
manipulation.

Swift SVN r16334
2014-04-14 22:02:51 +00:00
Doug Gregor
cd4ca76b6a Introduce the ObjCSelector class to store an Objective-C selector.
We have to work with selectors quite often, so provide an efficient
representation for them. Switch ObjCAttr over to this representation,
which has the nice property that it efficiently represents implicit
@objc attributes with names and allows us to overwrite the Objective-C
name without losing all source information. Addresses
<rdar://problem/16478678>, and sets us up for dealing with selectors
better.

Swift SVN r16327
2014-04-14 20:05:35 +00:00
Chris Lattner
7e121632ef Expand checking for implicit uses of self in closures to include method calls, and add
a fallback to catch anything else that is missed.  This resolve the rest of:
<rdar://problem/16193162> Require specifying self for locations in code where strong reference cycles are likely



Swift SVN r16319
2014-04-14 15:39:35 +00:00
Ted Kremenek
ba56076c5a Fix misspelling of 'initializer'.
Implements <rdar://problem/16603822>.

Swift SVN r16306
2014-04-14 07:17:52 +00:00
Chris Lattner
6e90d343be At long last, land the implementation of <rdar://problem/16397000> Should be able to override stored properties
This means that we now synthesize getters and setters a lot more than we used to, so the
implementation work on this shook out a ton of bugs with them.

There is still one failure that I don't understand at all (test/stdlib/NewArray.swift.gyb), 
nor do I understand how to diagnose the problem, so I XFAILed it and filed rdar://16604980 to
track fixing it.



Swift SVN r16299
2014-04-14 04:48:54 +00:00
Michael Gottesman
5293ec9581 Revert "Remove 'yet's from error messages."
This reverts commit r16291. Joe needs to update the tests before this
goes in.

Swift SVN r16292
2014-04-14 01:48:57 +00:00
Joe Groff
997b30c6ff Remove 'yet's from error messages.
You might very well think there's a future, but we couldn't possibly comment.

Swift SVN r16291
2014-04-13 23:50:26 +00:00
Joe Groff
9076575975 Sema: Reject @thin, @cc, and other function representation attributes in Swift.
We aren't going to be able to make these attributes meaningful to Swift source for 1.0, so reject them and recover by dropping them when resolving non-SIL types.

Swift SVN r16290
2014-04-13 23:45:33 +00:00
Chris Lattner
7e5028cd83 fix <rdar://problem/16574105> Type inference of _Nil very coherent but kind of useless
We now diagnose this as an error:

t.swift:1:5: error: variable 'x' inferred to nil with unspecified type; use a type annotation to specify which nil
var x = nil
    ^

since it is never useful to get the internal _Nil type.


Swift SVN r16223
2014-04-11 18:00:25 +00:00
Doug Gregor
1ce86d16f8 Validate @IBOutlet specifically.
Finishes the @IBOutlet portion of <rdar://problem/16281474>.

Swift SVN r16167
2014-04-10 18:22:24 +00:00
Dmitri Hrybenko
815823749a Diagnostics: refer to 'override' as a keyword
Swift SVN r16160
2014-04-10 13:58:43 +00:00
Dmitri Hrybenko
110f85bc16 Move @exported to use new attribute infrastructure
Swift SVN r16158
2014-04-10 13:35:35 +00:00
Ted Kremenek
2d4342b87a Give an error if “@obj” is used without importing ObjectiveC.
The standard library is exemptmpt (-parse-stdlib) from this checking.

Implements <rdar://problem/16559137>.

Swift SVN r16155
2014-04-10 09:08:09 +00:00
Dmitri Hrybenko
f90e0c153b Make 'override' a keyword
rdar://16462192

Swift SVN r16115
2014-04-09 14:19:50 +00:00
Joe Groff
8adaab0233 Fold ExtInfo::isThin and ::isBlock into a "Representation" enum.
These bits are orthogonal to each other, so combine them into one, and diagnose attempts to produce a type that's both. Spot-fix a bunch of places this revealed by inspection that we would have crashed in SILGen or IRGen if blocks were be handled.

Swift SVN r16088
2014-04-09 00:37:26 +00:00
Nadav Rotem
15233517ca Indent the line.
Swift SVN r16073
2014-04-08 20:31:57 +00:00
Nadav Rotem
5db3af6d38 Improve the diagnostics of immutable field access.
1.swift:7:18: error: cannot assign to 'x' in 'self'
  func Mod() { x = 1 }
               ~ ^



Swift SVN r16072
2014-04-08 20:27:32 +00:00
Dmitri Hrybenko
865a96a1a1 @noreturn: move to the new serialization scheme and add override checking
Swift SVN r16006
2014-04-07 11:22:59 +00:00
Nadav Rotem
276201c8ec Error message should start with a lower case letter.
Swift SVN r15987
2014-04-05 07:03:44 +00:00
Nadav Rotem
0d8729a9f6 Forbid the any kind of inheritance from @final classes.
Emit the following diagnostics:

  Inheritance from a final class 'ClassName'



Swift SVN r15986
2014-04-05 06:58:41 +00:00
Nadav Rotem
4b0e7737e1 Add support for the @final attribute on classes.
Swift SVN r15981
2014-04-05 05:52:40 +00:00
Chris Lattner
d94d11ea6b reword a diagnostic to read more nicely.
Swift SVN r15941
2014-04-04 16:36:52 +00:00
Dmitri Hrybenko
f198c28d75 Serialize @required as a DeclAttribute
Also introduce an invalid bit on a DeclAttribute for use by semantic analysis.

This fixes AST printing for @required.


Swift SVN r15938
2014-04-04 15:24:47 +00:00
Doug Gregor
26c4620b35 Introduce a "descriptive declaration kind" for use in diagnostics, etc.
Provide a fine-grained classification of declarations that can be used
in diagnostics instead of ad hoc %select operations. For now, only cut
over the "overriding a final <whatever>" diagnostic.


Swift SVN r15932
2014-04-04 06:35:42 +00:00
Doug Gregor
d2f7f90586 Re-introduce the restriction I zapped in r15928. getters/setters can't separately be marked @final.
Swift SVN r15930
2014-04-04 05:43:06 +00:00
Doug Gregor
604ad33d06 Handle getter/setter overriding more cleanly.
Use recordOverride() for getter and setter overriding. This means that
@objc names get propagated correctly, so we can stop chasing overrides
to find @objc names.



Swift SVN r15928
2014-04-04 05:27:50 +00:00
Chris Lattner
25b8f01fef enforce that @final may only be applied to func/var/subscripts (@final classes someday),
and that it doesn't appear on accessors.


Swift SVN r15927
2014-04-04 05:19:28 +00:00