Commit Graph

15 Commits

Author SHA1 Message Date
Sam Lazarus
ede8127adf Test: Add and update tests for allowing var and let as argument labels 2019-04-26 04:08:27 -04:00
David Farler
b7d17b25ba Rename -parse flag to -typecheck
A parse-only option is needed for parse performance tracking and the
current option also includes semantic analysis.
2016-11-28 10:50:55 -08:00
John McCall
c8c41b385c Implement SE-0077: precedence group declarations.
What I've implemented here deviates from the current proposal text
in the following ways:

- I had to introduce a FunctionArrowPrecedence to capture the parsing
  of -> in expression contexts.

- I found it convenient to continue to model the assignment property
  explicitly.

- The comparison and casting operators have historically been
  non-associative; I have chosen to preserve that, since I don't
  think this proposal intended to change it.

- This uses the precedence group names and higherThan/lowerThan
  as agreed in discussion.
2016-07-26 14:04:57 -07:00
Manav Gabhawala
7928140f79 [SE-0046] Implements consistent function parameter labels by discarding extraneous parameter names and adding _ where necessary 2016-04-06 20:21:58 -04:00
Joe Groff
2afece3e7c Remove warning about explicit '_' arguments.
SE-0046 will make the '_' necessary to suppress the first keyword label. This warning interferes with writing future-proof code.
2016-03-31 17:06:22 -07:00
Chris Lattner
5ce3de8dd6 remove & dial back three old bits of syntax auto-upgrading support:
1. Array type parsing for postfix array types Int[].  We now handle this
   in the parser, but remove the AST representation of this old form.  We
   also stop making vague promises about the future by saying that "fixed
   size arrays aren't supported... yet".  Removal of this fixes a compiler
   crasher too.

2. Remove the special case support for migrating @autoclosure from types
   to parameters, which was Swift 1.0/1.1 syntax.  The world has moved or
   we don't care anymore.

3. Remove upgrade support for # arguments (nee "backtick" arguments), which
   was a Swift 1.x'ism abolished in an effort to simplify method naming
   rules.

NFC on valid code.
2015-12-31 22:29:39 -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
Joe Groff
bebfa969bd Sema: Allow 'x.init' references on metatype expressions.
If 'x.init' appears as a member reference other than 'self.init' or 'super.init' within an initializer, treat it as a regular static member lookup for 'init' members. This allows a more explicit syntax for dynamic initializations; 'self.someMetatype()' looks too much like it's invoking a method. It also allows for partial applications of initializers using 'someMetatype.init' (though this needs some SILGen fixes, coming up next). While we're in the neighborhood, do some other correctness and QoI fixes:

- Only lookup initializers as members of metatypes, not instances, and add a fixit (instead of crashing) to insert '.dynamicType' if the initializer is found on an instance.
- Make it so that constructing a class-constrained archetype type correctly requires a 'required' or protocol initializer.
- Warn on unused initializer results. This seems to me like just the right thing to do, but is also a small guard against the fact that 'self.init' is now valid in a static method, but produces a newly-constructed value instead of delegating initialization (and evaluating to void).

Swift SVN r29344
2015-06-08 04:11:28 +00:00
Doug Gregor
b2cc34c241 Remove '#' for making parameter names into argument labels.
If you want to make the parameter and argument label the same in
places where you don't get the argument label for free (i.e., the
first parameter of a function or a parameter of a subscript),
double-up the identifier:

  func translate(dx dx: Int, dy: Int) { }

Make this a warning with Fix-Its to ease migration. Part of
rdar://problem/17218256.

Swift SVN r27715
2015-04-24 23:58:57 +00:00
Doug Gregor
793b3326af Implement the new rules for argument label defaults.
The rule changes are as follows:
  * All functions (introduced with the 'func' keyword) have argument
  labels for arguments beyond the first, by default. Methods are no
  longer special in this regard.
  * The presence of a default argument no longer implies an argument
  label.

The actual changes to the parser and printer are fairly simple; the
rest of the noise is updating the standard library, overlays, tests,
etc.

With the standard library, this change is intended to be API neutral:
I've added/removed #'s and _'s as appropriate to keep the user
interface the same. If we want to separately consider using argument
labels for more free functions now that the defaults in the language
have shifted, we can tackle that separately.

Fixes rdar://problem/17218256.

Swift SVN r27704
2015-04-24 19:03:30 +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
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
Doug Gregor
1efd9fba5b Start accepting '#' in addition to '`' to mark a keyword argument <rdar://problem/16891828>.
Update the standard library, tests, diagnostics, and Fix-Its.

Swift SVN r17981
2014-05-13 00:03:04 +00:00
Ted Kremenek
fad874708e Adjust test cases.
Swift SVN r17964
2014-05-12 22:01:52 +00:00
Doug Gregor
62fd9674c8 Use the argument names from a function's compound name when forming its type.
The test case churn is because we need to retain parentheses in the
computation of the type of a pattern (which we were dropping
before). This makes the new function declaration syntax actually
provide separate API names for the arguments.


Swift SVN r16421
2014-04-16 20:12:33 +00:00