Commit Graph

36 Commits

Author SHA1 Message Date
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
gregomni
05ebb021ba Add a slightly less close than CC_OneArgumentMismatch closeness.
Producing single argument mismatches involving generics causes some
gross looking error messages if the generic mismatches get put into the
same closeness bucket as non-generic mismatches.

E.g. `var v71 = true + 1.0` used to produce `error: cannot convert
value of type 'Bool' to expected argument type 'Double’`, but would now
end up with `binary operator '+' cannot be applied to operands of type
'Bool' and 'Double’` `overloads for '+' exist with these partially
matching parameter lists: (Double, Double), (T, T.Stride), (T.Stride,
T)`.

Resolve this by adding CC_OneGenericArgumentNearMismatch and
CC_OneGenericArgumentMismatch, that are similar but ever so slightly
not as close as a mismatch involving non-generic functions. This gets
back the original error message in cases like the above, because there
is only one declaration of `+` which partially matches and is
non-generic, and the generic partial matches are now farther away.

But now single arg mismatches and nearness work for single-archetype
generic functions, as in the additions to the SR-69 test at the end of
deduction.swift.
2016-01-22 10:24:03 -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
Doug Gregor
38c1de69e4 Reinstate "[SR-511][Parse] Add 'associatedtype' keyword and fixit"
This reverts commit ce7b2bcf09, tweaking
a few validation tests appropriately (1 crasher fixed, two -verify
tests that needed updating).
2016-01-14 00:21:48 -08:00
Erik Eckstein
ce7b2bcf09 Revert "[SR-511][Parse] Add 'associatedtype' keyword and fixit"
This reverts commit 2b2e9dc80e.

It broke some compiler crasher tests
2016-01-13 20:42:58 -08:00
gregomni
2b2e9dc80e [SR-511][Parse] Add 'associatedtype' keyword and fixit
Adds an associatedtype keyword to the parser tokens, and accepts either
typealias or associatedtype to create an AssociatedTypeDecl, warning
that the former is deprecated. The ASTPrinter now emits associatedtype
for AssociatedTypeDecls.

Separated AssociatedType from TypeAlias as two different kinds of
CodeCompletionDeclKinds. This part probably doesn’t turn out to be
absolutely necessary currently, but it is nice cleanup from formerly
specifically glomming the two together.

And then many, many changes to tests. The actual new tests for the fixits
is at the end of Generics/associated_types.swift.
2016-01-13 17:54:31 -08:00
Chris Lattner
a5a988e726 Fix rdar://22509125 QoI: Error when unable to infer generic archetype lacks greatness
Rearrange diagnoseGeneralConversionFailure to diagnose structural problems
even if we have some UnresolvedTypes floating around, then reject constraint
failures with UnresolvedTypes in them even harder.  This keeps us giving
good errors about failures where we have a structural problem (with buried
irrelevant details) while not complaining about cases that are actually
ambiguous.

The end result of this is that we produce a lot better error messages in the
case of failed archetype inference.  This also highlights the poor job we do
handling multi-stmt closureexprs...
2016-01-11 20:45:11 -08:00
Slava Pestov
f6e4355b69 Sema: Fix monthly TypeNullifier bug
This time, the issue is that TypeNullifier skips bodies of
multi-statement closures. However, ExprRewriter will type
happily pass them on to typeCheckClosureBody(). This could
trigger assertions. Fix this by skipping type checking of
multi-statement closures when diagnosing.

There seems to be a minor QoI regression in some test cases
that already looked pretty dodgy and/or had FIXMEs. However
I think its worth fixing a crash.
2015-12-11 08:58:52 -08:00
Slava Pestov
0269e0291e Sema: Fix assertion failure if EnumElementPattern is re-typechecked
We weren't actually successfully mutating ParentType,
so fix that, and also ensure we set ParentType together
with the rest of the state.

Discovered while writing resilient enum tests.
2015-12-11 08:58:51 -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
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