Commit Graph

33 Commits

Author SHA1 Message Date
Daniel Duan
780b58a9a5 [Parser] update tests for 'inout' syntax adjustment 2016-02-26 01:33:22 -08:00
Chris Lattner
94dd92fcb8 Fix compiler_crashers 22725 & 28236 by reworking parameter parsing error
recovery a bit.
2016-02-01 20:50:32 -08:00
David Farler
3f635d04c7 Reinstante var bindings in refutable patterns, except function parameters.
This reverts commits: b96e06da44,
                      8f2fbdc93a,
                      93b6962478,
                      64024118f4,
                      a759ca9141,
                      3434f9642b,
                      9f33429891,
                      47c043e8a6.

This commit leaves 'var' on function parameters as a warning to be
merged into Swift 2.2. For Swift 3, this will be an error, to be
converted in a follow-up.
2016-01-29 15:27:08 -08:00
Chris Willmore
983a674e0c Make use of curried function declaration syntax an error.
<rdar://problem/23111018>
2016-01-20 21:57:38 -08:00
David Farler
a6f2530780 Revert "REVERTME: Temporarily make vars in refutable patterns a warning"
This reverts commit b96e06da44, making
vars in refutable patterns an error for Swift 3.

rdar://problem/23172698
2016-01-14 20:52:24 -08:00
Chris Lattner
7daaa22d93 Completely reimplement/redesign the AST representation of parameters.
Parameters (to methods, initializers, accessors, subscripts, etc) have always been represented
as Pattern's (of a particular sort), stemming from an early design direction that was abandoned.
Being built on top of patterns leads to patterns being overly complicated (e.g. tuple patterns
have to have varargs and default parameters) and make working on parameter lists complicated
and error prone.  This might have been ok in 2015, but there is no way we can live like this in
2016.

Instead of using Patterns, carve out a new ParameterList and Parameter type to represent all the
parameter specific stuff.  This simplifies many things and allows a lot of simplifications.
Unfortunately, I wasn't able to do this very incrementally, so this is a huge patch.  The good
news is that it erases a ton of code, and the technical debt that went with it.  Ignoring test
suite changes, we have:
   77 files changed, 2359 insertions(+), 3221 deletions(-)

This patch also makes a bunch of wierd things dead, but I'll sweep those out in follow-on
patches.

Fixes <rdar://problem/22846558> No code completions in Foo( when Foo has error type
Fixes <rdar://problem/24026538> Slight regression in generated header, which I filed to go with 3a23d75.

Fixes an overloading bug involving default arguments and curried functions (see the diff to
Constraints/diagnostics.swift, which we now correctly accept).

Fixes cases where problems with parameters would get emitted multiple times, e.g. in the
test/Parse/subscripting.swift testcase.

The source range for ParamDecl now includes its type, which permutes some of the IDE / SourceModel tests
(for the better, I think).

Eliminates the bogus "type annotation missing in pattern" error message when a type isn't
specified for a parameter (see test/decl/func/functions.swift).

This now consistently parenthesizes argument lists in function types, which leads to many diffs in the
SILGen tests among others.

This does break the "sibling indentation" test in SourceKit/CodeFormat/indent-sibling.swift, and
I haven't been able to figure it out.  Given that this is experimental functionality anyway,
I'm just XFAILing the test for now.  i'll look at it separately from this mongo diff.
2015-12-31 19:24:46 -08:00
Doug Gregor
c8dd8d0661 Implement SE-0001: Allow (most) keywords as argument labels.
Allow all keywords except for parameter introducers (var/let/inout) to
be argument labels when declaring or calling a
function/initializer/subscript, e.g., this

  func touchesMatching(phase: NSTouchPhase, `in` view: NSView?) -> Set<NSTouch>

can now be expressed as

  func touchesMatching(phase: NSTouchPhase, in view: NSView?) -> Set<NSTouch>

and the call goes from

  event.touchesMatching(phase, `in`: view)

to

  event.touchesMatching(phase, in: view)

Fixes [SR-344](https://bugs.swift.org/browse/SR-344) /
rdar://problem/22415674.
2015-12-22 16:18:28 -08:00
David Farler
b96e06da44 REVERTME: Temporarily make vars in refutable patterns a warning
Revert "Make function parameters and refutable patterns always
immutable"

This reverts commit 8f2fbdc93a.

Once we have finally merged master into the Swift 2.2 branch to be, we
should revert this commit to turn the errors back on for Swift 3.0.
2015-12-05 23:13:04 -08:00
David Farler
8f2fbdc93a Make function parameters and refutable patterns always immutable
All refutable patterns and function parameters marked with 'var'
is now an error.

- Using explicit 'let' keyword on function parameters causes a warning.
- Don't suggest making function parameters mutable
- Remove uses in the standard library
- Update tests

rdar://problem/23378003
2015-11-09 16:56:13 -08:00
David Farler
93b6962478 Warn when using 'var' bindings in function parameters
These will no longer be allowed in a future Swift release.

rdar://problem/23172698
2015-11-03 17:24:20 -08:00
Chris Willmore
30af42fda9 Add warning that curried function decl syntax is going away.
<rdar://problem/23111018>
2015-11-02 15:45:11 -08:00
Chris Lattner
ada5487153 add fixit tests to random other tests.
Swift SVN r31006
2015-08-04 20:35:36 +00:00
Chris Lattner
509ff78787 Fix in <rdar://problem/21600924> Typo "be be" in live issue
Swift SVN r30883
2015-07-31 21:24:26 +00:00
Chris Lattner
33c6de5001 disable array/string -> pointer conversions in operator contexts that lack an &. They
are still allowed in non-operator calls.



Swift SVN r30398
2015-07-20 15:54:13 +00:00
Doug Gregor
149d4bcb95 Disallow unnamed function parameters written without the "_:".
Now, instead of writing, e.g.,

  func f(Int) { ... }

one must write the more-generally-consistent and explicit

  func f(_: Int) { ... }

Fixes rdar://problem/16737312.

Swift SVN r29609
2015-06-24 16:01:39 +00:00
Chris Lattner
ddd6192094 Implement 3 prominent feature requests:
<rdar://problem/15975935> warning that you can use 'let' not 'var'
<rdar://problem/18876585> Compiler should warn me if I set a parameter as 'var' but never modify it
<rdar://problem/17224539> QoI: warn about unused variables

This uses a simple pass in MiscDiagnostics that walks the body of an
AbstractFunctionDecl.  This means that it doesn't warn about unused properties (etc),
but it captures a vast majority of the cases.

It also does not warn about unused parameters (as a policy decision) because it is too noisy,
there are a variety of other refinements that could be done as well, thoughts welcome.



Swift SVN r28412
2015-05-11 06:26:05 +00:00
Roman Levenstein
984fcef576 Produce an error for generic parameters of functions if those parameters are not used in function signature.
If a generic parameter is not referred to from a function signature, it can never be inferred and thus such a function can never be invoked.

We now produce the following error:

generic parameter 'T' is not used in function signature
func f8<T> (x: Int) {}

This commit takes Jordan't comments on r28181 into account:
- it produces a shorter error message
- it does not change the compiler_crashers_fixed test and add a new expected error instead

Swift SVN r28194
2015-05-06 02:20:39 +00:00
Roman Levenstein
a3a25000ff Revert "Produce an error for generic parameters of functions if those parameters are not used in function signature."
This reverts commit r28181. I'll change it according to Jordan's comments and re-commit.

Swift SVN r28193
2015-05-06 02:20:36 +00:00
Roman Levenstein
ebe3fddbe6 Produce an error for generic parameters of functions if those parameters are not used in function signature.
If a generic parameter is not referred to from a function signature, it can never be inferred and thus such a function can never be invoked.

We now produce the following error:

There is no way to infer the generic parameter 'T' if it is not used in function signature
func f8<T> (x: Int) {}
             ^

Swift SVN r28181
2015-05-05 21:02:11 +00:00
Chris Lattner
9cfcebeb6a fix a fixme and close an old radar, this example really should be allowed.
Swift SVN r26831
2015-04-01 22:24:35 +00:00
Dmitri Hrybenko
3b04d1b013 tests: reorganize tests so that they actually use the target platform
Most tests were using %swift or similar substitutions, which did not
include the target triple and SDK.  The driver was defaulting to the
host OS.  Thus, we could not run the tests when the standard library was
not built for OS X.

Swift SVN r24504
2015-01-19 06:52:49 +00:00
Denis Vnukov
8770dba416 [TypeChecker] Minor: corrected safety check against crash in type checker on invalid input.
Swift SVN r23280
2014-11-12 18:17:03 +00:00
Argyrios Kyrtzidis
628567bfe5 [Frontend] Make it erroneous if no frontend action is specified when invoking the frontend, and update tests.
Swift SVN r21584
2014-08-29 19:17:37 +00:00
Doug Gregor
397f4a9888 Remove user-defined conversions from the type checker.
Nobody is using this crufty old feature now, so remove it and the
complexity that goes along with it.

Swift SVN r21379
2014-08-21 21:59:49 +00:00
Doug Gregor
9d5ba31daa Ban __conversion functions.
Swift SVN r21015
2014-08-04 15:54:15 +00:00
Chris Lattner
a2beb62f85 fix <rdar://problem/16786168> Functions currently permit 'var inout' parameters
fix <rdar://problem/17867059> ` upgrade logic should be removed




Swift SVN r20817
2014-07-31 06:18:42 +00:00
Dave Abrahams
1438d617cd [stdlib] Rename ConstUnsafePointer=>UnsafePointer
Swift SVN r20318
2014-07-22 17:10:54 +00:00
Chris Lattner
6867ce2e2c fix <rdar://problem/17763388> ambiguous operator emits same candidate multiple times
It seems not-great that the same candidate can get into the overload set for a DeclRefExpr
multiple times, but if it does, don't expose this to the user.



Swift SVN r20315
2014-07-22 16:44:25 +00:00
Chris Lattner
57cd2506ff Change "operator infix" to "infix operator" for consistency with the rest of the declaration
modifiers and with the func implementations of the operators.  This resolves the rest of:
<rdar://problem/17527000> change operator declarations from "operator prefix" to "prefix operator" & make operator a keyword




Swift SVN r19931
2014-07-14 16:39:10 +00:00
Chris Lattner
8991456ff2 Switch infix/postfix/prefix to be declaration modifiers instead of attributes,
eliminating the @'s from them when used on func's.  This is progress towards
<rdar://problem/17527000> change operator declarations from "operator prefix" to "prefix operator" & make operator a keyword

This also consolidates rejection of custom operator definitions into one
place and makes it consistent, and adds postfix "?" to the list of rejected
operators.

This also changes the demangler to demangle weak/inout/postfix and related things
without the @.



Swift SVN r19929
2014-07-14 15:51:49 +00:00
Dmitri Hrybenko
5916a5c238 Add test for rdar://16786220, we don't crash anymore
Swift SVN r19087
2014-06-23 11:25:13 +00:00
Ted Kremenek
fad874708e Adjust test cases.
Swift SVN r17964
2014-05-12 22:01:52 +00:00
Doug Gregor
faf1c45d14 Shuffle the files in the testsuite a bit to try to reflect language structure.
There's a lot more work to do here, but start to categorize tests
along the lines of what a specification might look like, with
directories (chapters) for basic concepts, declarations, expressions,
statements, etc.


Swift SVN r9958
2013-11-05 15:12:57 +00:00