Commit Graph

10 Commits

Author SHA1 Message Date
Alex Hoppen
32eff21977 [IDE] Remove "Begin completions" and "End completions" from test cases
These test lines weren't actually providing any value and were annoying to write. Let's jut remove them.
2023-03-22 09:07:17 -07:00
Alex Hoppen
b70e91fbff [Sema] Fix crash when retrieving typeContextInfo for a partially bound generic type
In the following test case, we are crashing while building the generic signature of `someGenericFunc`, potentially invoked on `model` in line 11.

```swift
struct MyBinding<BindingOuter> {
  func someGenericFunc<BindingInner>(x: BindingInner) {}
}

struct MyTextField<TextFieldOuter> {
  init<TextFieldInner>(text: MyBinding<TextFieldInner>) {}
}

struct EncodedView {
    func foo(model: MyBinding<String>) {
        let _ = MyTextField<String>(text: model)
    }
}
```

Because we know that `model` has type `MyBinding<TextFieldInner>`, we substitute the `BindingOuter` generic parameter by `TextFieldInner`. Thus, `someGenericFunc` has the signature `<TextFieldInner /* substitutes BindingOuter */, BindingInner>`. `TextFieldInner` and `BindingOuter` both have `depth = 1`, `index = 0`. Thus the verification in `GenericSignatureBuilder` is failing.

After discussion with Slava, the root issue appears to be that we shouldn’t be calling `subst` on a `GenericFunctionType` at all. Instead we should be using `substGenericArgs` which doesn’t attempt to rebuild a generic signature, but instead builds a non-generic function type.

--------------------------------------------------------------------------------

We slightly regress in code completion results by showing two `collidingGeneric` twice in the following case.

```swift
protocol P1 {
  func collidingGeneric<T>(x: T)
}
protocol P2 {
  func collidingGeneric<T>(x: T)
}
class C : P1, P2 {
  #^COMPLETE^#
}
```

Previously, we were representing the type of `collidingGeneric` by a generic function type with generic param `T` that doesn’t have any restrictions. Since we are now using `substGenericArgs` instead of `subst`, we receive a non-generic function type that represents `T` as an archetype. And since that archetype is different for the two function signatures, we show the result twice in code completion.

One could also argue that showing the result twice is intended (or at least acceptable) behaviour since, the two protocol may name their generic params differently. E.g. in

```swift
protocol P1 {
  func collidingGeneric<S>(x: S)
}
protocol P2 {
  func collidingGeneric<T>(x: T)
}
class C : P1, P2 {
  #^COMPLETE^#
}
```

we might be expected to show the following two results
```
func collidingGeneric<S>(x: S)
func collidingGeneric<T>(x: T)
```

Resolves rdar://76711477 [SR-14495]
2021-04-27 08:13:54 +02:00
Rintaro Ishizaki
3a2454c2c7 [CodeCompletion] Use opaque type for override completion if preferable
rdar://problem/49354106
2019-04-19 17:34:08 -07:00
fischertony
3d3f125d28 restore 'public' 2018-06-08 09:54:39 +03:00
fischertony
ede3ba207b [CodeCompletion] Duplicate existential requirements when restated 2018-05-24 03:54:05 +03:00
David Zarzycki
995dec5d82 [Sema] Error if ObjC interop is needed when disabled 2018-05-07 14:43:04 -04:00
Doug Gregor
537971e77a [AST] Teach OverrideFilteringConsumer not to substitute into generic function types.
Substitution into a generic function type produces non-canonical
generic signatures. This functionality should either be removed or be
completely rewritten to properly use the GenericSignatureBuilder. For
now, disable this one client's unsafe use of it.

This does regression code-completion results slightly, where we were
depending on OverrideFilteringConsumer's behavior to filter out some
redundant results. I've captured the work to fix this properly in
rdar://problem/31245556.
2017-03-24 11:36:44 -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
Rintaro Ishizaki
b827298892 [CodeCompletion] Modifier related improvements in CompletionOverrideLookup
* If "required" or "convenience" is specified, emit only initializers
* If "final" or "open" is specified, don't emit initializers or typealias
* If "typealias" is specified, emit only associated type implementation
* Emit "override" or "required" modifier for initializers
* Emit access modifier for initializers
* Emit designated initializers even if "override" is specified
* Don't emit inheritance clause for associated type implentation
2016-08-27 03:48:51 +09:00
Rintaro Ishizaki
fac2b7a4a5 [CodeCompletion] Test: Add class version of omplete_override_access_control 2016-08-20 05:12:01 +09:00