Commit Graph

357 Commits

Author SHA1 Message Date
David Rönnqvist
57731ebc09 [QoI] [Parse] Improve error message when parsing floating point exponent
Update error messages to mention the invalid character.
Improve the diagnostic of floating point exponents.

Add tests for error messages when parsing floating point exponents.
Update existing tests for new error messages.
2017-07-08 13:32:34 +02:00
David Rönnqvist
a615d9ede3 [QoI] Improve error message when parsing integer literal
Rephrased error message to indicate which character is unexpected.
Provide error message variations when parsing binary, octal, decimal (default), and hexadecimal integer literals.
Look for unexpected digits in binary and octal integer literals.
Look for unexpected letters in hex integer literals.

Resolves: SR-5236 rdar://problem/32858684
2017-07-06 19:59:09 +02:00
Alex Hoppen
18128308e4 Merge pull request #9294 from ahoppen/SR-4785-fixit-missing-type
[Parser] Add fix-it for missing type errors
2017-05-20 08:26:52 +01:00
Max Moiseev
fa0904f1e5 [stdlib] Adding operator overloads on concrete integer types
It looks like the compiler is having troubles with the pattern when the
non-mutaing operator is defined on the protocol, and delegates to the
mutating version, that is provided by the concrete type. Adding similar
definitions of non-mutating operators to concrete types significantly
speeds up the typechecking of complex expressions, like the one in
the ByteSwap benchmark.
2017-05-17 15:56:17 -07:00
Alex Hoppen
adbe86243e [Parser] Add fix-it for missing type errors
We can't reliably decide in the parser if a type was forgotten or a
wrong type was meant to be a type (e.g. `let x: class MyClass`).
This patch applies a heuristic that the parameter was most likely
forgotten if the next character is a closing bracket or a semantic
separator.
This catches the most common cases of function parameters and variable
declarations that are immediately initialised.

This fixes SR-4785.
2017-05-04 21:43:58 +01:00
Max Moiseev
fe4553eb80 Merge branch 'master' into new-integer-protocols 2017-04-11 17:07:11 -07:00
Slava Pestov
de323b5bef Sema: Update resolveType() for subclass existentials
If the -enable-experimental-subclass-existentials staging flag
is on, resolveType() now allows protocol compositions to contain
class types. It also diagnoses if a composition has more than one
superclass requirement.

Also, change diagnostics that talked about 'protocol composition'
to 'protocol-constrained type'.

Since such types can now contain a superclass constraint, it's not
correct to call them protocol composition.

"Protocol-constrained type" isn't quite accurate either because
'Any' has no protocols, and 'AnyObject' will have no protocols but
a general class constraint; but those are edge cases which won't
come up in these diagnostics.
2017-04-10 17:11:07 -07:00
Max Moiseev
0e7863129c Merge remote-tracking branch 'origin/master' into new-integer-protocols 2017-01-30 16:51:16 -08:00
Rintaro Ishizaki
590ac72316 [Parse] Parse subscript with '#' expressions
Fixes: https://bugs.swift.org/browse/SR-3439
2017-01-27 19:59:55 +09:00
Max Moiseev
90ef26824f Merge remote-tracking branch 'origin/master' into new-integer-protocols 2017-01-26 15:28:42 -08:00
Slava Pestov
4148079a9e Sema: Change diagnostics to not talk about 'materializable' types
This is not a term we want users to have to care about.
2017-01-23 23:54:50 -08:00
Max Moiseev
1814e4fce3 Fixing tests 2017-01-23 10:59:31 -08:00
Max Moiseev
d128ed42b0 Merge remote-tracking branch 'origin/master' into new-integer-protocols 2017-01-19 14:16:32 -08:00
Jacob Bandes-Storch
4a16880103 [QoI] Add diagnostic for unused literal values
Fixes SR-3522.
2017-01-10 20:42:36 -08:00
Max Moiseev
e1de9fcf0c More test fixes 2017-01-09 16:17:21 -08:00
Max Moiseev
27889c6376 Merge remote-tracking branch 'origin/master' into new-integer-protocols 2017-01-06 15:54:44 -08:00
Slava Pestov
18adb53226 Sema: Tighten up name lookup routines to not look through metatypes/lvalues/etc
Previously all of the following would strip off varying amounts of
MetatypeType, LValueType, InOutType, DynamicSelfType, etc:

- ConstraintSystem::performMemberLookup()
- ConstraintSystem::lookupMember()
- TypeChecker::lookupMember()
- DeclContext::lookupQualified()
- Type::getContextSubstitutions()

The problem is that the higher level methods that took a lookup type
would call the lower level methods, and post-process the result using
the given lookup type. Since different levels of sugar were stripped,
it made the code hard to reason about and opened up edge cases, eg
if a DynamicSelfType or InOutType appears where we didn't expect it.

Since filtering out static/instance and mutating/nonmutating members
is done at higher levels, there's no reason for these name lookup
operations to accept anything other than nominal types, existentials
and archetypes.

Make this so with assertions, and deal with the fallout.
2017-01-04 01:40:19 -08:00
Max Moiseev
9a8cdbc703 Merge branch 'master' into new-integer-protocols 2016-12-14 17:18:02 -08:00
Slava Pestov
321edbfca4 Revert "[Sema] Implement SE-0110"
This reverts commit e172383e2f.

There were two problems with this commit:
- This was a source-breaking change and should have been feature-gated.
- It only addressed one narrow case of SE-0110.

Fixes <rdar://problem/28621719>.
2016-12-13 22:11:51 -08:00
Max Moiseev
70b2343626 Merge branch 'master' into new-integer-protocols 2016-11-28 15:25:01 -08: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
Max Moiseev
92813be403 Merge branch 'master' into new-integer-protocols 2016-11-11 16:14:57 -08:00
Rintaro Ishizaki
f4a9898142 [QoI] Improve "never used" diagnostics (#5638)
On 'let (x) = some', we should remove r-paren as well.
On 'let x: Int = some', we can't remove 'let' introducer.
2016-11-05 15:17:54 +09:00
Max Moiseev
3d4f00091d Merge remote-tracking branch 'origin/master' into new-integer-protocols 2016-10-28 15:55:40 -07:00
Pavel Yaskevich
dd01b7e184 [Diagnostics] SR-2208: Improve failure diagnostics for apply expressions 2016-10-26 14:34:05 -07:00
Max Moiseev
8d1155c2b9 Merge remote-tracking branch 'origin/master' into new-integer-protocols 2016-10-17 11:29:07 -07:00
Mark Lacey
32634b1bdd Merge pull request #5239 from xedin/SR-1255
SR-1255: Improve diagnostic when one of the parameters marked as autoclosure
2016-10-14 12:40:21 -07:00
Pavel Yaskevich
f526a251c6 [Diagnostics] SR-1255: Improve diagnostic when one of the parameters marked as autoclosure 2016-10-11 14:43:37 -07:00
Rintaro Ishizaki
68bd3d62a5 [Parse] Don't emit missing closing paren error if seeing any errors 2016-10-09 04:07:34 +09:00
Rintaro Ishizaki
f70d2d9e1c [Parse] Skip ahead if seeing any error while parsing list.
If we found any error in a list, in most cases, we cannot expect that the
following tokens could construct a valid element. Skip them, instead of trying
to parse them as the next element. This significally reduces bogus diagnostics.

Bailout if seeing tok::eof or token that can never start a element, after
parsing an element. This silences superfluous "expected ',' separator" error,
or misleading expected declaration error. What we should emit is
"expected ')' in expression list, or "expected '}' in struct".
2016-10-09 04:05:07 +09:00
Max Moiseev
08cf1de65a [WIP] fixing some of the integer related test failures 2016-10-05 15:25:23 -07:00
Paul Meng
e172383e2f [Sema] Implement SE-0110
This commit built upon the work of Pull Request 3895. Apart from the
work to make the following work

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

This patch also implement the part 2 mentioned in the #3895

```swift
let g: ((Int, Int)) -> Void = { y in  } // y should have type (Int, Int)
```
2016-08-14 12:02:27 +08:00
Xiaodi Wu
f9435b9ce8 [stdlib] Restore MemoryLayout.*(ofValue:) 2016-08-08 10:46:37 -05:00
Doug Gregor
22287ddb58 [Type system] Infer 'Any' for array elements and dictionary values and 'AnyHashable' for dictionary keys.
The id-as-Any work regressed cases where Swift code could specify
heterogeneous collection literals, e.g.,

    var states: [String: Any] = [
      "California": [
        "population": 37_000_000,
        "cities": ["Los Angeles", "San Diego", "San Jose"],
      ],
      "Oregon": [
        "population": 4_000_000,
        "cities": ["Portland", "Salem", "Eugene"],
      ]
    ]

Prior to this, the code worked (when Foundation was imported) because
we'd end up with literals of type [NSObject : AnyObject].

The new defaulting rule says that the element type of an array literal
and the key/value types of a dictionary literal can be defaulted if no
stronger type can be inferred. The default type is:

  Any, for the element type of an array literal or the value type of a
  dictionary literal, or

  AnyHashable, for the key type of a dictionary literal.

The latter is intended to compose with implicit conversions to
AnyHashable, so the most-general inferred dictionary type is
[AnyHashable : Any] and will work for any plausible dictionary
literal.

To prevent this inference from diluting types too greatly, we don't
allow this inference in "top-level" expressions, e.g.,

  let d = ["a" : 1, "b" : "two"]

will produce an error because it's a heterogeneous dictionary literal
at the top level. One should annotate this with, e.g.,

  let d = ["a" : 1, "b" : "two"] as [String : Any]

However, we do permit heterogeneous collections in nested positions,
to support cases like the original motivating example.

Fixes rdar://problem/27661580.
2016-08-04 20:58:13 -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
Doug Gregor
f1706303a0 Merge pull request #3895 from dduan/se0110_a-pr
[Sema] ban multi-arguments to tuple coercion
2016-07-31 23:00:32 -07:00
Chris Lattner
3f827c0ca1 When diagnosing a missing parameter, point to the decl that is being called.
This resolves:
<rdar://problem/24106465> QoI: missing argument to memberwise initializer doesn't tell me its signature
2016-07-31 16:34:52 -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
Robert Widmann
dcfecec67e Disable test
The error is propagated through parsing the `sizeof` expression and
makes this bogus.  This can be revisited when the dynamicType error is
removed in a future swift.
2016-07-30 15:41:43 -07:00
Robert Widmann
515bce2d98 Update leftover test from SE-0096 + SE-0101 migratory clash 2016-07-30 15:28:11 -07:00
Rintaro Ishizaki
fd4ddd6322 [SE-0101] Migration support for sizeof(T) family to MemoryLayout<T> 2016-07-30 18:24:13 +09:00
Doug Gregor
b9363fe6bd [SE-0111] Enable SE-0111 by default. 2016-07-29 17:28:24 -07: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
Chris Lattner
842d6777d9 enhance a few diagnostics to include the non-optional type name. 2016-07-23 17:30:03 -07:00
Chris Lattner
d138290448 Produce warnings when implicit optional promotions are introduced in some
common standard library operators.  This is progress towards:
<rdar://problem/27457457> [Type checker] Diagnose unsavory optional injections

but there is more work to be done here.
2016-07-23 16:03:41 -07:00
Mark Lacey
3ba204694e Do not suppress optional coercion in operators with a nil-literal operand.
This is the hack that has been used to reject things like:
  var i: Int = ...
  if i == nil { }
in the past.

The hack is inconsistent with normal treatment of mixed optional &
non-optional operands, and will be replaced with a warning instead of
treating it as a failure to type check.

There is still a case that we still fail type checking on -
Unsafe*Pointer<> compares to nil. That will be addressed by a separate
commit.

The new warning will be addressed by rdar://problem/27457457. When the
new warnings are updated the test cases modified here will again need to
be updated based on the text of the new warning.
2016-07-21 22:39:33 -07:00
Rintaro Ishizaki
bdaa9cb689 [Parse] Improve fix-it for deprecated protocol<...> syntax
`protocol<A,B>` case, used to fixed-it as `A &B`, that is illegal.

Instead of removing angles and replacing commas, replace whole expession
with new syntax.
2016-07-21 14:49:02 +09:00
Rintaro Ishizaki
97c325f908 [Parse] Improve diagnostic for deprecated protocol<...> syntax (#3631)
* Don't emit deprecated warnings for incomplete protocol<...>.
  E.g: `func fn(x: protocol<P) {}`
* Different message for single protocol compostion.
  E.g: `typealias MyError = protocol<Error>`
2016-07-21 13:44:08 +09: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
7b9e5de7b7 [SE-0095] simplifyTypeExpr for composition expressions
Also adds:
- Any is caught before doing an unconstrained lookup, and the
protocol<> type is emitted
- composition expressions can be handled by
`PreCheckExpression::simplifyTypeExpr` to so you can do lookups like (P
& Q).self
- Fixits corrected & new tests added
- Typeref lowering cases should have been optional
- This fixes a failing test case.
2016-07-19 12:01:37 -07:00