17 Commits

Author SHA1 Message Date
Sam Pyankov
139c325d76 Merge pull request #86323 from slavapestov/fix-ppt-type-witness-conflict-crash
Sema: Fix crash when parameterized protocol types define conflicting type witnesses
2026-01-14 09:51:03 -08:00
Slava Pestov
38a9d8389d Sema: Fix crash when parameterized protocol types define conflicting type witnesses 2026-01-13 15:52:44 -08:00
Slava Pestov
74c2731fc9 Sema: Narrow down cycle-breaking hack in TypeChecker::lookupMemberType()
It's okay if we're in the middle of associated type inference, as
long as we've already recorded the type witness we're looking for!

This fixes a regression from 62e4979691,
but what's notable is the cycle breaking hack has been there this
whole time. The fact that it was overly broad was only exposed now.

The specific code example in the test case is intentionally wrong.
It was reduced from a piece of code that attempted to refer to a
generic parameter named `Output` by writing `Self.Output`, and this
picked up a protocol type alias instead, so the original project
needed to be fixed anyway. But, the regressed behavior was bogus
too, because we started to emit a diagnostic that didn't make
sense, so let's fix it anyway.

Fixes rdar://problem/167849997.
2026-01-13 16:55:46 -05:00
Slava Pestov
6701e5b39b Sema: Tighten ridiculous disambiguation hack for overloaded type declarations
We noticed that a project failed to build with prepared overloads enabled,
but built successfully with prepared overloads disabled.

It turns out that the code clearly should never have been accepted in the
first place, because the type checker was making an arbitrary choice between
two nominal type declarations with the same name.

Further inspection revealed this was because of a FIXME added in 2013 which
was far too broad. Tighten up the logic here to only disambiguate if at least
one of the two declarations is a type alias, and it has the same underlying
type as the other one. A choice between unrelated nominal type declarations
should always be ambiguous.

This still isn't perfect, because we might have two generic type aliases
that are referenced in both solutions with different substitution maps,
in which case we will still erroneously pick the first one. But this
is better than the old logic, at least.

Fixes rdar://165863775.
2025-12-09 22:48:12 -05:00
Alejandro Alonso
9f2aec5286 Add -verify-ignore-unrelated to a few tests 2025-10-07 13:16:36 -07:00
Henrik G. Olsson
cbc0ec3b88 Add -verify-ignore-unrelated where necessary (NFC)
These are tests that fail in the next commit without this flag. This
does not add -verify-ignore-unrelated to all tests with -verify, only
the ones that would fail without it. This is NFC since this flag is
currently a no-op.
2025-10-04 14:19:52 -07:00
Slava Pestov
cd5ecbee16 Sema: Implement missing part of SE-0346
The proposal states that this should work, but this was never
implemented:

    protocol P<A> {
      associatedtype A
    }

    struct S: P<Int> {}

- Fixes https://github.com/swiftlang/swift/issues/62906.
- Fixes rdar://91842338.
2025-06-03 17:28:19 -04:00
Slava Pestov
7c7caa2088 Sema: Fix regression with 'Failure' type witness inference hack
We have a special hack to infer the 'Failure' type witness in
'AsyncIteratorProtocol' by considering the type of 'next()'
witness.

In eaf06eae0e I added a check to
fix some assertions that could happen if 'next()' was witnessed
by a declaration in a protocol extension or superclass, which
has a different generic signature.

However my check was too narrow, because it also prohibited
this form of inference when 'next()' was in a different
extension of the same nominal type.

Allow this again.

Fixes https://github.com/swiftlang/swift/issues/79367.
Fixes rdar://problem/145341658.
2025-04-03 17:34:31 -04:00
Slava Pestov
b26c59962b Sema: Fix handling of getter typed throws in associated type inference
We must replace type parameters with archetypes in the thrown error type
of the witness. The requirement type remains an interface type.
2025-04-01 17:21:32 -04:00
Daniel Rodríguez Troitiño
ba68faaed5 [test] Mark tests that use experimental/upcoming features as such
Find all the usages of `--enable-experimental-feature` or
`--enable-upcoming-feature` in the tests and replace some of the
`REQUIRES: asserts` to use `REQUIRES: swift-feature-Foo` instead, which
should correctly apply to depending on the asserts/noasserts mode of the
toolchain for each feature.

Remove some comments that talked about enabling asserts since they don't
apply anymore (but I might had miss some).

All this was done with an automated script, so some formatting weirdness
might happen, but I hope I fixed most of those.

There might be some tests that were `REQUIRES: asserts` that might run
in `noasserts` toolchains now. This will normally be because their
feature went from experimental to upcoming/base and the tests were not
updated.
2024-11-02 11:46:46 -07:00
Allan Shortlidge
6f55aa4170 Tests: Remove -disable-availability-checking in tests that use opaque types.
Use the `%target-swift-5.1-abi-triple` substitution to compile the tests for
deployment to the minimum OS versions required for use of opaque types, instead
of disabling availability checking.
2024-10-19 19:39:18 -07:00
Slava Pestov
df1b4bc3ba Fix name of test case 2024-08-29 16:18:14 -04:00
Slava Pestov
8c8b700ece Fix name of test case and move it to test/Generics/ 2024-08-29 16:18:14 -04:00
Alex Hoppen
577727ad55 Remove DiagnosticsEditorMode
Migrate the last diagnostic to be independent of `DiagnosticEditorMode` and remove that option.

rdar://133111163
2024-08-14 11:24:31 -07:00
Alex Hoppen
66104395d7 [Sema/SourceKit] Emit same diagnostics for missing protocol requirements on the command line and in SourceKit
Some editors use diagnostics from SourceKit to replace build issues. This causes issues if the diagnostics from SourceKit are formatted differently than the build issues. Make sure they are rendered the same way, removing most uses of `DiagnosticsEditorMode`.

To do so, always emit the `add stubs for conformance` note (which previously was only emitted in editor mode) and remove all `; add <something>` suffixes from notes that state which requirements are missing.

rdar://129283608
2024-08-07 14:01:30 -07:00
Slava Pestov
609f436b61 Sema: Fix crash with circular type witness edge case
Fixes https://github.com/swiftlang/swift/issues/75371
2024-08-03 15:51:57 -04:00
Slava Pestov
557300ba48 Move associated type inference tests into their own directory 2024-06-28 17:50:24 -04:00