Commit Graph

10 Commits

Author SHA1 Message Date
Pavel Yaskevich
c30845fa74 [ConstraintSystem] Detect and diagnose missing generic arguments
Introduce a fix to detect and diagnose situations when omitted
generic arguments couldn't be deduced by the solver based on
the enclosing context.

Example:

```swift
struct S<T> {
}

_ = S() // There is not enough context to deduce `T`
```

Resolves: rdar://problem/51203824
2019-05-29 16:39:41 -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
Jordan Rose
caeed32302 Add a fix-it for missing generic parameters on construction.
For example, if someone tries to use the newly-generic type Cache,
from Foundation:

  var cache = Cache()

they'll now get a fix-it to substitute the default generic parameters:

  var cache = Cache<AnyObject, AnyObject>()

The rules for choosing this placeholder type are based on constraints
and won't be right 100% of the time, but they should be reasonable.
(In particular, constraints on associated types are ignored.)
In cases where there's no one concrete type that will work, an Xcode-
style placeholder is inserted instead.

- An unconstrained generic parameter defaults to 'Any'.
- A superclass-constrained parameter defaults to that class,
  e.g. 'UIView'.
- A parameter constrained to a single @objc protocol (or to AnyObject)
  defaults to that protocol, e.g. 'NSCoding'.
- Anything else gets a placeholder using the generic parameter's name
  and protocol composition syntax.

rdar://problem/27087345
2016-09-21 18:04:14 -06: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
Chris Lattner
f102876943 Improve diagnostics for unbound archetypes coming from a type, to indicate
information about where the archetype was defined.  Before:

t.swift:6:17: error: generic parameter 'T' could not be inferred
var a : Int = A.foo()
                ^

After:

t.swift:6:17: error: generic parameter 'T' could not be inferred
var a : Int = A.foo()
                ^
t.swift:2:8: note: 'T' declared as parameter to type 'A'
struct A<T> {
       ^
2016-01-21 17:37:39 -08:00
Chris Lattner
1034a94929 reword a diagnostic to be shorter and hopefully more useful as suggested by DaveA.
Swift SVN r31638
2015-09-02 21:13:48 +00:00
Dmitri Hrybenko
843d8a4eb7 stdlib: protocol extensions: de-underscore map()
Swift SVN r28502
2015-05-13 01:58:46 +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
Doug Gregor
e002261865 Diagnose free type variables that correspond to generic parameters.
t2.swift:3:1: error: argument for generic parameter 'U' could not be
inferred
f(i)
^
t2.swift:2:6: note: in call to function 'f'
func f<T, U>(t: T) -> U? { return nil }
     ^

Our lack of decent locator information means that we don't get notes
in all of the cases we want them. I'll look at that separately.

Swift SVN r21921
2014-09-12 20:27:21 +00:00
Joe Groff
25fa3f399a Sema: Diagnose ambiguous member references devoid of context.
Handle an UnresolvedDot in the fallback case of the constraint solver where there are no active constraints but the system is ambiguous. Fixes the common case of 'Array.map' taking down SourceKit halfway through typing an expression. <rdar://problem/17125912>

Swift SVN r20450
2014-07-24 00:15:01 +00:00