Commit Graph

75 Commits

Author SHA1 Message Date
Suyash Srijan
9ae2c85991 [Typechecker] Use CallArgs for checking duplicate label & add new test cases 2019-05-17 23:38:34 +01:00
Suyash Srijan
505f8dba9f [test] Update test 2019-05-17 00:21:19 +01:00
Suyash Srijan
d8f3880565 [Test] Adds a new test case where we have an enum case with duplicate label 2019-05-15 02:34:58 +01:00
Suyash Srijan
eca1c1fd66 [Test] Adds a new test case 2019-05-15 02:26:23 +01:00
Suyash Srijan
71fee96093 [Typechecker] Ban tuples with duplicate labels 2019-05-14 19:43:46 +01:00
Slava Pestov
e2c9c52c93 AST/Sema/SILGen: Implement tuple conversions
TupleShuffleExpr could not express the full range of tuple conversions that
were accepted by the constraint solver; in particular, while it could re-order
elements or introduce and eliminate labels, it could not convert the tuple
element types to their supertypes.

This was the source of the annoying "cannot express tuple conversion"
diagnostic.

Replace TupleShuffleExpr with DestructureTupleExpr, which evaluates a
source expression of tuple type and binds its elements to OpaqueValueExprs.

The DestructureTupleExpr's result expression can then produce an arbitrary
value written in terms of these OpaqueValueExprs, as long as each
OpaqueValueExpr is used exactly once.

This is sufficient to express conversions such as (Int, Float) => (Int?, Any),
as well as the various cases that were already supported, such as
(x: Int, y: Float) => (y: Float, x: Int).

https://bugs.swift.org/browse/SR-2672, rdar://problem/12340004
2019-03-27 18:12:05 -04:00
Doug Gregor
e21a96f4ab [SIMD] Update tests to reflect the SIMD operators in the standard library
Introducing the SIMD operators back into the standard library regresses
one test (SR-139 goes exponential against without the designated types
for operatores feature). Split that part of the test out.
2018-12-17 11:43:45 -08:00
Slava Pestov
8cfe7377e3 Sema: Ban single-element tuple expressions
Fixes <rdar://problem/30384023>, <rdar://problem/41474370>,
and <https://bugs.swift.org/browse/SR-8109>.
2018-12-15 00:07:04 -05:00
Brent Royal-Gordon
a72be0fb7d Sort overloads in suggestPotentialOverloads()
When the compiler fails to find an overload with suitable parameter or return types, it often attaches a note listing the available overloads so that users can find the one they meant to use. The overloads are currently ordered in a way that depends on the order they were declared, so swift-evolve would sometimes cause tests involving these diagnostics to fail.

This change emits the list in a textually-sorted order instead. The names were already being sorted as they were inserted into a std::set, so this shouldn’t significantly slow down the diagnostic.
2018-12-12 11:58:57 -08:00
Pavel Yaskevich
63b802ca88 [AST/Printing] Don't omit empty labels in special names
This makes diagnostics more verbose and accurate, because
it's possible to distinguish how many parameters there are
based on the message itself.

Also there are multiple diagnostic messages in a format of
`<descriptive-kind> <decl-name> ...` that get printed as
e.g. `subscript 'subscript'` if empty labels are omitted.
2018-09-24 18:36:53 -07:00
Pavel Yaskevich
27d0d26222 Revert "[CSDiagnostics] Don't mention special names in requirement diagnostics" 2018-09-21 14:44:04 -07:00
Pavel Yaskevich
02d5401499 [CSDiagnostics] Don't mention special names in requirement diagnostics
Instead of `initializer 'init' of ...` diagnostic should only
mention kind e.g. `initializer of ...` of the declaration
with a special name.
2018-09-21 00:35:21 -07:00
Slava Pestov
6b13734da3 Sema: Fix regression with tuple conversions from recent changes
61152e6585 introduced a behavior change
that was caught neither by our test suite nor the source compatibility
tests.
2018-08-30 18:20:06 -07:00
Pavel Yaskevich
3cc613497c [ConstraintSystem] Add same-type requirement fix/diagnostic
Extend new requirement failure diagnostics by adding "same-type"
generic requirement failures.
2018-08-18 13:05:32 -07:00
Slava Pestov
b581c63e6b AST: Remove TypeBase::getRValueObjectType()
This would look through one-element tuples, which is no longer necessary.
2018-08-08 10:18:52 -07:00
Slava Pestov
ceff27cfd1 Add test for SR-2600 which is already fixed 2017-05-07 01:57:38 -07:00
Slava Pestov
2281ff0c1c Sema: Fix another crash with tuple to Any conversion
An earlier patch fixed the case where some tuple elements
were lvalue types. However this only looked into tuples
nested one level deep, when a more correct fix checks the
lvalue recursive property of the type.
2017-04-11 14:26:11 -07: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
practicalswift
ef8e43b519 [gardening] Increase consistency with regards to spacing after colons 2016-09-22 16:28:57 +02:00
practicalswift
3a4ee89034 [gardening] Use consistent formatting. 2016-09-17 12:12:49 +02:00
Mark Lacey
56a5ef00a4 Add a fixit for attempting member lookup on Any.
Suggest casting to AnyObject or a more specific type.

rdar://problem/27639935
2016-08-07 12:19:53 -07:00
Jordan Rose
f42158b12e Revert "[Sema] ban multi-arguments to tuple coercion" (#3922)
It breaks cases where there really is a single unlabeled argument of tuple type, like this:

  let pairs = [(1, "A"), (2, "B")]
  print(pairs.map { $0.0 })
2016-08-01 19:22:19 -07:00
Daniel Duan
c9b73dacc2 [Sema] ban multi-arguments to tuple coercion
Implements part of SE-0110. Single argument in closures will not be accepted if
there exists explicit type with a number of arguments that's not 1.

```swift
let f: (Int, Int) -> Void = { x in } // this is now an error
```

Note there's a second part of SE-0110 which could be considered additive,
which says one must add an extra pair of parens to specify a single arugment
type that is a tuple:

```swift
let g ((Int, Int)) -> Void = { y in } // y should have type (Int, Int)
```

This patch does not implement that part.
2016-07-31 16:22:57 -07:00
Chris Lattner
fb7a4e9ded Generalize the closure work from yesterday, enough to fix:
rdar://17687826 - QoI: error message when reducing to an untyped dictionary isn't helpful
2016-07-31 15:25:17 -07:00
Doug Gregor
b9363fe6bd [SE-0111] Enable SE-0111 by default. 2016-07-29 17:28:24 -07:00
Chris Lattner
773d521bfa fix rdar://25271859 QoI: Misleading error message when expression result can't be inferred from closure
We previously produced the error message:

rdar25271859.swift:14:11: error: value of tuple type '(Float, Int)' has no member '0'
  a.map { $0.0 }
          ^~ ~

We now produce:

rdar25271859.swift:15:5: error: generic parameter 'U' could not be inferred
   .andThen { dataResult in
    ^

which is at least is correct, if not yet helpful.
2016-07-29 16:45:17 -07:00
Michael Ilseman
c37751ae96 [noescape by defaul] make noescape the default
This flips the switch to have @noescape be the default semantics for
function types in argument positions, for everything except property
setters. Property setters are naturally escaping, so they keep their
escaping-by-default behavior.

Adds contentual printing, and updates the test cases.

There is some further (non-source-breaking) work to be done for
SE-0103:

- We need the withoutActuallyEscaping function
- Improve diagnostics and QoI to at least @noescape's standards
- Deprecate / drop @noescape, right now we allow it
- Update internal code completion printing to be contextual
- Add more tests to explore tricky corner cases
- Small regressions in fixits in attr/attr_availability.swift
2016-07-29 13:49:08 -07:00
David Farler
7bfaeb57f1 [SE-0081] Warn on deprecated where clause inside angle brackets
and provide a fix-it to move it to the new location as referenced
in SE-0081.

Fix up a few stray places in the standard library that is still using
the old syntax.

Update any ./test files that aren't expecting the new warning/fix-it
in -verify mode.

While investigating what I thought was a new crash due to this new
diagnostic, I discovered two sources of quite a few compiler crashers
related to unterminated generic parameter lists, where the right
angle bracket source location was getting unconditionally set to
the current token, even though it wasn't actually a '>'.
2016-07-26 01:41:10 -07:00
Joe
3938d5682a [SE-0095] [Runtime], [Demangler], & AST printer updated to new composition syntax
- All parts of the compiler now use ‘P1 & P2’ syntax
- The demangler and AST printer wrap the composition in parens if it is
in a metatype lookup
- IRGen mangles compositions differently
    - “protocol<>” is now “swift.Any”
    - “protocol<_TP1P,_TP1Q>” is now “_TP1P&_TP1Q”
- Tests cases are updated and added to test the new syntax and mangling
2016-07-19 12:01:37 -07:00
Joe
a6dad0091b [SE-0095] Initial parsing implementation for '&' composition syntax
This commit defines the ‘Any’ keyword, implements parsing for composing
types with an infix ‘&’, and provides a fixit to convert ‘protocol<>’

- Updated tests & stdlib for new composition syntax
- Provide errors when compositions used in inheritance.
Any is treated as a contextual keyword. The name ‘Any’
is used emit the empty composition type. We have to
stop user declaring top level types spelled ‘Any’ too.
2016-07-19 12:01:02 -07:00
Doug Gregor
823c24b355 [SE-0112] Rename ErrorProtocol to Error.
This is bullet (5) of the proposed solution in SE-0112, and the last
major piece to be implemented.
2016-07-12 10:53:52 -07:00
Stephen Canon
6429eabf74 Implement the new FloatingPoint protocols from SE-0067.
There are a couple of features that are not yet implemented, because they require additions to the Builtin module.  Specifically, this implementation does not have:

- formRemainder(dividingBy:)
- formSquareRoot()
- addProduct(_:,_:)

Also missing are the generic initializers and comparisons whose implementation depends on having new Integer protocols.

The last remaining feature of SE-0067 is that while the basic operators +,-,*,/, etc are moved onto the FloatingPoint protocol, they are still required on the concrete types in order to disambiguate overloads.  Fixing this seems to require either modifying the overload resolution rules or removing these operators from some other protocols.  Or it might just require that someone smarter than me looks at the problem.

Passes all the existing tests (with the included changes).  I'm working on additional tests for the new features.
2016-05-09 10:34:13 -04:00
Chris Lattner
2c81c8a114 add some parens to the testsuite, NFC. 2016-05-05 23:19:08 -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
Manav Gabhawala
7862f104c9 [Parser] Cleans up parsing of parameter attributes. Implements SE-0053. Fixes SR-979, SR-1020 and cleans up implementation of SE-0003. Provides better fix-its and diagnostics for misplaced 'inout' and prohibits 'var' and 'let' from parameter attributes 2016-03-29 13:55:46 -04:00
Max Moiseev
61c837209b Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-04 16:13:39 -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
practicalswift
189a183908 [gardening] Fix recently introduced typo 2016-01-23 09:21:11 +01:00
Chris Lattner
554b7d0525 Fix SR-596 - Compiler crashes when accesing a non-existent property of a closure parameter
This crash was a bug in computeTupleShuffle handling conversions to
a parameter list with a varargs argument in the middle of the list.
In this case, it is coming from the parameter list for Swift.print.
2016-01-22 17:22:14 -08:00
Joe Pamer
29a4f98318 Adjust diagnostic to reflect recent constraint solver changes. 2016-01-22 14:32:20 -08:00
John McCall
130d31c346 Don't ignore tuple labels in same-type *or stronger* constraints.
Thanks to Doug Gregor for finding the bug here.

Fixes rdar://24210190 (by making it ill-formed).
2016-01-21 11:27:33 -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
Max Moiseev
f51e708a8f Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-01-04 12:25:25 -08:00
practicalswift
31ff35e1dd Use 80 column headers consistently. 2016-01-04 01:35:02 +01:00
Dmitri Gribenko
feacbc4433 Rename ErrorType to ErrorProtocol 2015-12-09 17:12:19 -08:00
Chris Lattner
c7c180f8d8 Fix <rdar://problem/23700031> QoI: Terrible diagnostic in tuple assignment
When inferring a contextual type for the input expression to an assignment,
use getRValueType() to strip lvalues from tuple types in recursive positions,
this allows us to produce a sensible diagnostic of:

error: binary operator '%' cannot be applied to two 'T' operands

instead of:

error: cannot assign value of type 'T' to type '@lvalue _'

because we don't have a weird lvalue type in the way.
2015-11-30 20:54:14 -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
97e6a50148 Start using contextual information from function calls to diagnose issues in their
argument.  For now we start with some of the most simple cases: single argument 
calls.  This dramatically improves the QoI for error messages in argument lists,
typically turning a error+note combo into a single specific error message.

Some minor improvements coming (and also generalizing this to n-ary calls), but it 
is nice that all the infrastructure is starting to come together...



Swift SVN r30905
2015-08-01 04:37:52 +00:00
Chris Lattner
922a7f53b3 consolidate the diagnostics produced by the "Failure" case and the expr walker in CSDiags to
get the same wording, fixing <rdar://problem/21964599> Different diagnostics for the same issue

While I'm in the area, remove some dead code.



Swift SVN r30713
2015-07-28 04:43:37 +00:00