Commit Graph

127 Commits

Author SHA1 Message Date
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
64024118f4 Make always-immutable pattern bindings a warning for now
These will become errors after the next release branch.

rdar://problem/23172698
2015-11-03 12:46:38 -08:00
David Farler
a759ca9141 Disallow 'var' bindings in case patterns
Make the following illegal:

switch thing {
  case .A(var x):
    modify(x0
}

And provide a replacement 'var' -> 'let' fix-it.

rdar://problem/23172698

Swift SVN r32883
2015-10-25 18:53:02 +00:00
David Farler
3434f9642b Disallow 'var' pattern bindings in if, while, and guard statements
Make the following patterns illegal:

  if var x = ... {
    ...
  }

  guard var x = ... else {
    ...
  }

  while var x = ... {
    ...
  }

And provide a replacement fixit 'var' -> 'let'.

rdar://problem/23172698

Swift SVN r32855
2015-10-24 01:46:30 +00:00
David Farler
9f33429891 Tweak var in for-in statement diagnostic
Actually say that `var` is not allowed in a for-in statement.

rdar://problem/23172698

Swift SVN r32827
2015-10-22 18:07:04 +00:00
David Farler
47c043e8a6 Disallow 'var' specifier in for-in patterns
Don't allow a pattern like:

  for var x in sequence {
    ...
  }

and provide a removal fix-it for the 'var' keyword.

Additionally, for the following code:

  for let x in sequence {
    ...
  }

Provide a removal fix-it since the 'let' specifier is now
redundant.

rdar://problem/23172698

Swift SVN r32818
2015-10-22 00:46:25 +00:00
Chris Willmore
8c57b7cde5 Improve diagnosis of implicit match expressions
When diagnosing failure to typecheck a binary '~=' expression that was
synthesized when typechecking an expression pattern, offer a message
that describes the failure more helpfully.

<rdar://problem/21995744> QoI: Binary operator '~=' cannot be applied to operands of type 'String' and 'String?'

Swift SVN r31286
2015-08-18 02:33:10 +00:00
Chris Lattner
b6206ab418 add fixit checks to various type checker testcases
Swift SVN r31004
2015-08-04 20:30:54 +00:00
Joe Pamer
828eb68e72 Commit DaveA's API changes to 'print', along with the compiler changes necessary to support them.
There's still work left to do. In terms of next steps, there's still rdar://problem/22126141, which covers removing the 'workaround' overloads for print (that prevent bogus overload resolution failures), as well as providing a decent diagnostic when users invoke print with 'appendNewline'.

Swift SVN r30976
2015-08-04 01:57:11 +00:00
Dmitri Hrybenko
f46f16ae82 stdlib: implement new print() API
rdar://20775683

Swift SVN r28309
2015-05-08 01:37:59 +00:00
Chris Lattner
82956ede54 fix a QoI regression I introduced in r26224. If an initializer expr in a var/let decl
is invalid and produces a ParseError, recovery by producing an AST with an ErrorExpr in it
instead of dropping the initializer on the floor.  This silences downstream errors about
"must have an initializer" sorts of stuff.



Swift SVN r26405
2015-03-22 05:08:26 +00:00
Chris Lattner
59c22383fb Rework PatternBindingDecl to maintain a list of pattern/initexpr pairs inside of it.
Previously, a multi-pattern var/let decl like:
  var x = 4, y = 17

would produce two pattern binding decls (one for x=4 one for y=17).  This is convenient
in some ways, but is bad for source reproducibility from the ASTs (see, e.g. the improvements
in test/IDE/structure.swift and test/decl/inherit/initializer.swift).

The hardest part of this change was to get parseDeclVar to set up the AST in a way
compatible with our existing assumptions. I ended up with an approach that forms PBDs in 
more erroneous cases than before.  One downside of this is that we now produce a spurious
  "type annotation missing in pattern"
diagnostic in some cases.  I'll take care of that in a follow-on patch.





Swift SVN r26224
2015-03-17 16:14:18 +00:00
Chris Lattner
a0d02cdcdd Several minor changes:
- Strength reduce isAtStartOfBindingName() to just check for 
   identifier or _ and inline into its two callers.
 - Rename Token::isIdentifierOrNone to isIdentifierOrUnderscore.
 - Teach InVarOrLetPattern about matching patterns, so that the
   parser knows when it is parsing an expression as a matching
   pattern but is not yet inside a let/var pattern.
 - Use newfound knowledge of matching patterns to refine handling
   of unexpected let/var when parsing an expression, but not in a
   pattern context, slightly improving QoI in invalid cases.



Swift SVN r26172
2015-03-15 23:36:05 +00:00
Chris Lattner
bf73cc23f1 fix <rdar://problem/20167543> "for var x = ..." not parsed as a foreach loop
This was because the ambiguity between c-style and foreach loops wasn't being
properly handled.  Use the canParsePattern() logic to handle this in full 
generality.

Since that logic was unused, dust it off and clean it up a bit.  Similarly,
remove some old vestigates of default argument parsing in tuples and 
old-syntax array handling.



Swift SVN r26164
2015-03-15 21:43:04 +00:00
Chris Lattner
27ef444db5 Remove the "isLet" parameter from the pattern parsing logic. It was (almost)
duplicated by the InVarOrLetPattern state in the Parser object.  Beef 
InVarOrLetPattern up so that we can remove it.

NFC except that we now reject pointless let patterns in foreach loops,
similar to how we reject var patterns inside of let patterns.



Swift SVN r26163
2015-03-15 21:06:37 +00:00
Chris Lattner
83541dd362 add tests for the ?? operator and x?.foo() monadic binds in value matching cases,
per Jordan's request.


Swift SVN r26003
2015-03-11 23:40:19 +00:00
Chris Lattner
6b31c2fa67 enhance sema's remapping of pattern expressions into patterns to handle multiple
???'s stacked on top of each other in patterns.  This wraps up:
<rdar://problem/19382878> Introduce new x? pattern

please kick the tires and let me know if you see any problems.


Swift SVN r26002
2015-03-11 23:23:32 +00:00
Chris Lattner
718d82f5c9 rework our treatment of identifiers in refutable patterns that are inside of
a let/var pattern.  Now any identifier in one of these is a variable binding,
not sometimes a value references (depending on contextual syntax).

This isn't expected to have a widespread effect on existing real world code:
 - No impact on the stdlib.
 - It does fix two validation crash tests, but possibly because the original issue is hidden by a different diagnostic path in the compiler.
 - This needed two tests to be tweaked to undistribute "let".

On the positive side, this means that "case let x?:" now works properly, woo.



Swift SVN r26000
2015-03-11 23:08:55 +00:00
Joe Groff
8af07b1c36 Sema: Allow Enum.Case case patterns in existential contexts.
In an existential context, allow 'case Enum.Case:' by implicitly introducing a cast pattern, treating it as 'case Enum.Case as Enum:'. This will be important for the error handling design, where we want ErrorType-conforming enums to be pattern-matchable out of an ErrorType existential using 'catch' patterns.

Swift SVN r25968
2015-03-11 03:21:25 +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
Joe Groff
efed339dfc Sema: Remove limits on checked casts involving generic types.
It doesn't make sense to try to limit them in most cases, because there may be protocol conformances we don't know about statically in the dynamic program. Relax casts that always succeed or fail to be a warning instead of an error.

Swift SVN r23298
2014-11-13 02:59:03 +00:00
Doug Gregor
5fc8ac7fd1 Require the 'override' keyword for initializers that override designated initializers.
Swift SVN r20490
2014-07-24 15:38:33 +00:00
Chris Lattner
70076cf958 switch the testsuite to use the ..< operator instead of ..
Swift SVN r19003
2014-06-19 17:18:23 +00:00
Ted Kremenek
9eea282719 Switch range operators ".." and "...".
- 1..3 now means 1,2
- 1...3 now means 1,2,3

Implements <rdar://problem/16839891>

Swift SVN r18066
2014-05-14 07:36:00 +00:00
Ted Kremenek
fad874708e Adjust test cases.
Swift SVN r17964
2014-05-12 22:01:52 +00:00
Joe Groff
efd1cf47ca Parse patterns in expression position as UnboundPatternExprs.
Parse patterns as top-level expression productions, for name binding to validate and convert into proper patterns later. If the type-checker sees an UnboundPattern production survive name binding (currently always), then raise a helpful "patterns don't belong here" error.

Swift SVN r5842
2013-06-27 20:38:39 +00:00